Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.totrail.totrail;
- import android.app.Dialog;
- import android.app.ProgressDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.content.SharedPreferences;
- import android.os.AsyncTask;
- import android.os.Bundle;
- import android.app.ProgressDialog;
- import android.content.DialogInterface;
- import android.content.DialogInterface.OnClickListener;
- import androidx.appcompat.widget.Toolbar;
- import androidx.core.view.GravityCompat;
- import androidx.appcompat.app.ActionBarDrawerToggle;
- import android.util.Log;
- import android.view.MenuItem;
- import com.google.android.material.navigation.NavigationView;
- import com.google.gson.Gson;
- import com.totrail.totrail.Adapter.FeedAdapter;
- import com.totrail.totrail.Common.HTTPDataHandler;
- import com.totrail.totrail.Model.RSSObject;
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.drawerlayout.widget.DrawerLayout;
- import androidx.recyclerview.widget.LinearLayoutManager;
- import androidx.recyclerview.widget.RecyclerView;
- import android.view.Menu;
- public class MainActivity extends AppCompatActivity
- implements NavigationView.OnNavigationItemSelectedListener {
- RecyclerView recyclerView;
- RSSObject rssObject;
- private final String RSS_link="http://api.totrail.org:54961/feed";
- private final String RSS_to_Json_API = "https://api.rss2json.com/v1/api.json?rss_url=";
- public static final String APP_PREFERENCES = "voda_zahlebnulas-kolobok_povesilsa";
- public static final String APP_PREFERENCES_TOKEN = "token"; // User's API token
- public static final String APP_PREFERENCES_STARTED = "nonononono";
- public String token = "waiting...";
- SharedPreferences mSettings;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Toolbar toolbar = findViewById(R.id.toolbar);
- toolbar.setTitle("Маршруты");
- setSupportActionBar(toolbar);
- recyclerView = findViewById(R.id.recyclerView);
- LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getBaseContext(),LinearLayoutManager.VERTICAL,false);
- recyclerView.setLayoutManager(linearLayoutManager);
- loadRSS();
- setSupportActionBar(toolbar);
- // mAdView = findViewById(R.id.adView);
- DrawerLayout drawer = findViewById(R.id.drawer_layout);
- // NavigationView navigationView = findViewById(R.id.nav_view);
- ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
- this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
- drawer.addDrawerListener(toggle);
- toggle.syncState();
- // navigationView.setNavigationItemSelectedListener(this);
- mSettings = getSharedPreferences(APP_PREFERENCES, Context.MODE_PRIVATE);
- mSettings.contains(APP_PREFERENCES_STARTED);// TODO: make very cool welcome screen
- // TODO: and here is too! :-)
- if(mSettings.contains(APP_PREFERENCES_TOKEN)) {
- token = mSettings.getString(APP_PREFERENCES_TOKEN, "");
- } else {
- token = "not_login_in";
- }
- }
- private void loadRSS() {
- AsyncTask<String, String, String> loadRSSAsync = new AsyncTask<String, String, String>() {
- ProgressDialog mDialog = new ProgressDialog(MainActivity.this);
- @Override
- protected void onPreExecute() {
- mDialog.setMessage("Ждите...");
- mDialog.show();
- }
- @Override
- protected String doInBackground(String... params) {
- String result;
- HTTPDataHandler http = new HTTPDataHandler();
- result = http.GetHTTPData(params[0]);
- return result;
- }
- @Override
- protected void onPostExecute(String s) {
- mDialog.dismiss();
- Log.i("KEK", s == null ? "null" : s);
- rssObject = new Gson().fromJson(s, RSSObject.class);
- FeedAdapter adapter = new FeedAdapter(rssObject, getBaseContext());
- recyclerView.setAdapter(adapter);
- adapter.notifyDataSetChanged();
- }
- };
- StringBuilder url_get_data = new StringBuilder(RSS_to_Json_API);
- url_get_data.append(RSS_link);
- loadRSSAsync.execute(url_get_data.toString());
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.main_menu,menu);
- return true;
- }
- // @Override
- // protected void onStop() {
- // super.onStop();
- // Dialog progressDialog = null;
- // if ((progressDialog != null) && progressDialog.isShowing()) {
- // progressDialog.dismiss();
- // progressDialog = null;
- // }
- // }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- if (item.getItemId() == R.id.menu_refresh)
- loadRSS();
- return true;
- }
- @Override
- public boolean onNavigationItemSelected(MenuItem item) {
- // Handle navigation view item clicks here.
- int id = item.getItemId();
- if (id == R.id.nav_home) {
- Intent intent = new Intent(this, loginActivity.class);
- startActivity(intent);
- } else if (id == R.id.nav_gallery) {
- } else if (id == R.id.nav_slideshow) {
- } else if (id == R.id.nav_tools) {
- } else if (id == R.id.nav_share) {
- } else if (id == R.id.nav_send) {
- }
- DrawerLayout drawer = findViewById(R.id.drawer_layout);
- drawer.closeDrawer(GravityCompat.START);
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement