Fixes issue with menu selection

This commit is contained in:
tom79 2017-07-26 18:31:26 +02:00
parent c608f0bdf0
commit df74faacf8
2 changed files with 21 additions and 14 deletions

View File

@ -74,6 +74,7 @@ import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import mastodon.etalab.gouv.fr.mastodon.R;
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT;
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_USER_INTENT;
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
@ -173,8 +174,8 @@ public class MainActivity extends AppCompatActivity
tabLayout.setVisibility(View.VISIBLE);
switch (tab.getPosition()){
case 0:
fragmentTag = "HOME_TIMELINE";
item = navigationView.getMenu().findItem(R.id.nav_home);
fragmentTag = "HOME_TIMELINE";
break;
case 1:
fragmentTag = "LOCAL_TIMELINE";
@ -368,16 +369,19 @@ public class MainActivity extends AppCompatActivity
tabLayout.getTabAt(3).select();
matchingIntent = true;
}else if( extras.getInt(INTENT_ACTION) == HOME_TIMELINE_INTENT){
unCheckAllMenuItems(navigationView);
changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification
tabLayout.getTabAt(0).select();
matchingIntent = true;
changeUser(MainActivity.this, userIdIntent, true); //Connects the account which is related to the notification
}else if( extras.getInt(INTENT_ACTION) == CHANGE_THEME_INTENT){
unCheckAllMenuItems(navigationView);
navigationView.setCheckedItem(R.id.nav_settings);
navigationView.getMenu().performIdentifierAction(R.id.nav_settings, 0);
toolbarTitle.setText(R.string.settings);
matchingIntent = true;
}else if( extras.getInt(INTENT_ACTION) == CHANGE_USER_INTENT){
unCheckAllMenuItems(navigationView);
navigationView.setCheckedItem(R.id.nav_home);
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
toolbarTitle.setText(R.string.home_menu);
matchingIntent = true;
}
}else if( Intent.ACTION_SEND.equals(action) && type != null ){
if ("text/plain".equals(type)) {
@ -524,7 +528,6 @@ public class MainActivity extends AppCompatActivity
//Proceeds to update of the authenticated account
if(Helper.isLoggedIn(getApplicationContext()))
new UpdateAccountInfoByIDAsyncTask(getApplicationContext(), MainActivity.this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@ -660,7 +663,7 @@ public class MainActivity extends AppCompatActivity
/**
* Page Adapter for settings
*/
private class PagerAdapter extends FragmentStatePagerAdapter {
private class PagerAdapter extends FragmentStatePagerAdapter {
int mNumOfTabs;
private PagerAdapter(FragmentManager fm, int NumOfTabs) {

View File

@ -17,7 +17,6 @@
package fr.gouv.etalab.mastodon.helper;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.DownloadManager;
@ -53,10 +52,10 @@ import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.ArrowKeyMovementMethod;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;
@ -117,7 +116,6 @@ import fr.gouv.etalab.mastodon.asynctasks.RemoveAccountAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.Account;
import fr.gouv.etalab.mastodon.client.Entities.Mention;
import fr.gouv.etalab.mastodon.client.Entities.Status;
import fr.gouv.etalab.mastodon.client.Entities.Tag;
import fr.gouv.etalab.mastodon.client.PatchBaseImageDownloader;
import fr.gouv.etalab.mastodon.sqlite.AccountDAO;
import fr.gouv.etalab.mastodon.sqlite.Sqlite;
@ -171,6 +169,7 @@ public class Helper {
public static final int NOTIFICATION_INTENT = 1;
public static final int HOME_TIMELINE_INTENT = 2;
public static final int CHANGE_THEME_INTENT = 3;
public static final int CHANGE_USER_INTENT = 4;
//Settings
public static final String SET_TOOTS_PER_PAGE = "set_toots_per_page";
public static final String SET_ACCOUNTS_PER_PAGE = "set_accounts_per_page";
@ -587,6 +586,7 @@ public class Helper {
File file;
if( bitmap != null) {
file = new File(myDir, fileName);
//noinspection ResultOfMethodCallIgnored
file.createNewFile();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@ -852,10 +852,6 @@ public class Helper {
final NavigationView navigationView = (NavigationView) activity.findViewById(R.id.nav_view);
navigationView.getMenu().clear();
navigationView.inflateMenu(R.menu.activity_main_drawer);
if( checkItem ) {
navigationView.setCheckedItem(R.id.nav_home);
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
}
SQLiteDatabase db = Sqlite.getInstance(activity, Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
Account account = new AccountDAO(activity,db).getAccountByID(userID);
//Can happen when an account has been deleted and there is a click on an old notification
@ -873,6 +869,11 @@ public class Helper {
editor.putString(Helper.PREF_KEY_ID, account.getId());
editor.apply();
activity.recreate();
if( checkItem ) {
Intent intent = new Intent(activity, MainActivity.class);
intent.putExtra(INTENT_ACTION, CHANGE_USER_INTENT);
activity.startActivity(intent);
}
}
@ -1100,6 +1101,9 @@ public class Helper {
statusTV.setText(spannableString, TextView.BufferType.SPANNABLE);
statusTV.setMovementMethod(null);
statusTV.setMovementMethod(LinkMovementMethod.getInstance());
statusTV.setMovementMethod(ArrowKeyMovementMethod.getInstance());
statusTV.setFocusable(true);
statusTV.setFocusableInTouchMode(true);
return statusTV;
}