Fixes a small bad behavior when changing the theme.

This commit is contained in:
tom79 2017-07-23 17:09:23 +02:00
parent 920cbd6afa
commit b6dc5e31a0
5 changed files with 50 additions and 21 deletions

View File

@ -29,6 +29,7 @@ import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
@ -73,6 +74,7 @@ import fr.gouv.etalab.mastodon.fragments.TabLayoutSettingsFragment;
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.HOME_TIMELINE_INTENT;
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
import static fr.gouv.etalab.mastodon.helper.Helper.NOTIFICATION_INTENT;
@ -81,6 +83,7 @@ import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
import static fr.gouv.etalab.mastodon.helper.Helper.changeUser;
import static fr.gouv.etalab.mastodon.helper.Helper.loadPPInActionBar;
import static fr.gouv.etalab.mastodon.helper.Helper.menuAccounts;
import static fr.gouv.etalab.mastodon.helper.Helper.unCheckAllMenuItems;
import static fr.gouv.etalab.mastodon.helper.Helper.updateHeaderAccountInfo;
import android.support.v4.app.FragmentStatePagerAdapter;
@ -335,17 +338,7 @@ public class MainActivity extends AppCompatActivity
}
}
private void unCheckAllMenuItems(@NonNull final Menu menu) {
int size = menu.size();
for (int i = 0; i < size; i++) {
final MenuItem item = menu.getItem(i);
if(item.hasSubMenu()) {
unCheckAllMenuItems(item.getSubMenu());
} else {
item.setChecked(false);
}
}
}
@Override
@ -372,18 +365,20 @@ public class MainActivity extends AppCompatActivity
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
userIdIntent = extras.getString(PREF_KEY_ID); //Id of the account in the intent
if (extras.getInt(INTENT_ACTION) == NOTIFICATION_INTENT){
changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification
unCheckAllMenuItems(navigationView.getMenu());
navigationView.getMenu().performIdentifierAction(R.id.nav_notification, 0);
if( navigationView.getMenu().findItem(R.id.nav_notification) != null)
navigationView.getMenu().findItem(R.id.nav_notification).setChecked(true);
changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification
tabLayout.getTabAt(3).select();
matchingIntent = true;
}else if( extras.getInt(INTENT_ACTION) == HOME_TIMELINE_INTENT){
changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification
unCheckAllMenuItems(navigationView.getMenu());
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
if( navigationView.getMenu().findItem(R.id.nav_home) != null)
navigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
changeUser(MainActivity.this, userIdIntent, false); //Connects the account which is related to the notification
tabLayout.getTabAt(0).select();
matchingIntent = true;
}else if( extras.getInt(INTENT_ACTION) == CHANGE_THEME_INTENT){
unCheckAllMenuItems(navigationView.getMenu());
navigationView.setCheckedItem(R.id.nav_settings);
navigationView.getMenu().performIdentifierAction(R.id.nav_settings, 0);
toolbarTitle.setText(R.string.settings);
matchingIntent = true;
}
}else if( Intent.ACTION_SEND.equals(action) && type != null ){

View File

@ -142,6 +142,10 @@ public class WebviewActivity extends AppCompatActivity {
}
}
public void setUrl(String newUrl){
this.url = newUrl;
}
@Override
public void onDestroy(){
super.onDestroy();

View File

@ -36,10 +36,15 @@ import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.helper.Helper;
import mastodon.etalab.gouv.fr.mastodon.R;
import static android.app.Activity.RESULT_OK;
import static fr.gouv.etalab.mastodon.helper.Helper.CHANGE_THEME_INTENT;
import static fr.gouv.etalab.mastodon.helper.Helper.HOME_TIMELINE_INTENT;
import static fr.gouv.etalab.mastodon.helper.Helper.INTENT_ACTION;
/**
@ -201,6 +206,10 @@ public class SettingsFragment extends Fragment {
getActivity().setTheme(R.style.AppTheme);
}
getActivity().recreate();
Intent intent = new Intent(context, MainActivity.class);
intent.putExtra(INTENT_ACTION, CHANGE_THEME_INTENT);
startActivity(intent);
}
});

View File

@ -42,6 +42,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
@ -56,6 +57,7 @@ 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;
import android.view.View;
@ -168,7 +170,7 @@ public class Helper {
//Notifications
public static final int NOTIFICATION_INTENT = 1;
public static final int HOME_TIMELINE_INTENT = 2;
public static final int CHANGE_THEME_INTENT = 3;
//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";
@ -1311,4 +1313,16 @@ public class Helper {
}
return false;
}
public static void unCheckAllMenuItems(@NonNull final Menu menu) {
int size = menu.size();
for (int i = 0; i < size; i++) {
final MenuItem item = menu.getItem(i);
if(item.hasSubMenu()) {
unCheckAllMenuItems(item.getSubMenu());
} else {
item.setChecked(false);
}
}
}
}

View File

@ -22,6 +22,8 @@ import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import fr.gouv.etalab.mastodon.activities.WebviewActivity;
import mastodon.etalab.gouv.fr.mastodon.R;
/**
@ -57,7 +59,12 @@ public class MastalabWebViewClient extends WebViewClient {
}else {
activity.setTitle(url);
}
//Changes the url in webview activity so that it can be opened with an external app
try{
if( activity instanceof WebviewActivity)
((WebviewActivity)activity).setUrl(url);
}catch (Exception ignore){}
}
}