mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-29 13:53:54 +01:00
* Add additional classes from 2019 hackathon implementation * Make first tab work * Make explore tab work * Handle back button for contrib and nearby * Fix framelayout and nav bar allignment * Fix nav bar tint * Fix nearby card layout * Make contributions number visible * Change menu icon according to fragment * Make notification icon work and remove drawer * Make favourites accessible from nav bar * Turn bookmark and explore activities into fragments * Use bottom sheet instead of more fragment * Add actions * Remove unused classes * Fix indentation * remove more fragment title * Fix explore fragment indentation * Make toolbar settings as we wanted * Set card view styles * Make colors for explore actiivty * Remove drawer from achievements activity * Add back button to achievements activity * remove drawer from review activity * Remove drawer from settings activity * Remove drawer from about activity * Fix dagger injection of fragment * Implement skip login version * Add theme missing colors * Add style to moresheet * refactor name * call login with button * Remove all old bookmarks activity dependency * Make explore tab items clickable * Do nothing if same tab is selected * Fix notification icon color for dark theme * Fix wrong drawable colors * Handle back button after media details is visible from contrib and explore fragments * make favourites open media details * Fix profile icon * Make user name visible instead * Move user back to contrib fragment * Remove NavigationBaseAvticity * Fix typo in bookmark fragment * Fix menu button colors * Remove explore activity * remove drawer and dependencies * Make bookmark media details visible * Cleanup code * Code cleanup * Remove unused layout * Make contriblist UI look like in mockups * Change limited connecton toggle * Move list menu item to nearby fragment * Fix search button crash * Make media detail appear * Back button added * Fix back button npe * Change bookmark list view * Fix always the firs item displayed issue * Allign contrib list bottom line to simple drawee bottom * fix fragment string * Fix back button for mobile uploads * Make lists appear * Make fav item selected * Make favourites clickable * Add back button to media details * Add toolbar of notification activity * Change contributions icon * Fix card UI * Fix back button in explore * Make card views look similar to mockups * Solve campaign bug visible issue * Make borders a little softer
This commit is contained in:
parent
5d82629109
commit
71d200ee41
110 changed files with 2225 additions and 1629 deletions
|
|
@ -1,355 +0,0 @@
|
|||
package fr.free.nrw.commons.theme;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
import fr.free.nrw.commons.profile.ProfileActivity;
|
||||
import org.wikipedia.dataclient.Service;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import butterknife.BindView;
|
||||
import fr.free.nrw.commons.AboutActivity;
|
||||
import fr.free.nrw.commons.BuildConfig;
|
||||
import fr.free.nrw.commons.CommonsApplication;
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.WelcomeActivity;
|
||||
import fr.free.nrw.commons.auth.LoginActivity;
|
||||
import fr.free.nrw.commons.auth.LogoutClient;
|
||||
import fr.free.nrw.commons.bookmarks.BookmarksActivity;
|
||||
import fr.free.nrw.commons.contributions.MainActivity;
|
||||
import fr.free.nrw.commons.explore.ExploreActivity;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
import fr.free.nrw.commons.logging.CommonsLogSender;
|
||||
import fr.free.nrw.commons.review.ReviewActivity;
|
||||
import fr.free.nrw.commons.settings.SettingsActivity;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
||||
public abstract class NavigationBaseActivity extends BaseActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
private boolean isRestoredToTop;
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@BindView(R.id.navigation_view)
|
||||
NavigationView navigationView;
|
||||
@BindView(R.id.drawer_layout)
|
||||
DrawerLayout drawerLayout;
|
||||
@Inject
|
||||
@Named("default_preferences")
|
||||
JsonKvStore applicationKvStore;
|
||||
@Inject CommonsLogSender commonsLogSender;
|
||||
|
||||
|
||||
private ActionBarDrawerToggle toggle;
|
||||
|
||||
@Inject
|
||||
LogoutClient logoutClient;
|
||||
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private Service service;
|
||||
|
||||
private ProgressDialog progressDialog;
|
||||
|
||||
public void initDrawer() {
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar,
|
||||
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawerLayout.addDrawerListener(toggle);
|
||||
toggle.setDrawerIndicatorEnabled(true);
|
||||
toggle.syncState();
|
||||
Menu nav_Menu = navigationView.getMenu();
|
||||
View headerLayout = navigationView.getHeaderView(0);
|
||||
ImageView userIcon = headerLayout.findViewById(R.id.user_icon);
|
||||
if (applicationKvStore.getBoolean("login_skipped", false)) {
|
||||
userIcon.setVisibility(View.GONE);
|
||||
nav_Menu.findItem(R.id.action_login).setVisible(true);
|
||||
nav_Menu.findItem(R.id.action_home).setVisible(false);
|
||||
nav_Menu.findItem(R.id.action_settings).setVisible(true);
|
||||
nav_Menu.findItem(R.id.action_logout).setVisible(false);
|
||||
nav_Menu.findItem(R.id.action_bookmarks).setVisible(true);
|
||||
nav_Menu.findItem(R.id.action_review).setVisible(false);
|
||||
} else {
|
||||
setUserName();
|
||||
userIcon.setVisibility(View.VISIBLE);
|
||||
nav_Menu.findItem(R.id.action_login).setVisible(false);
|
||||
nav_Menu.findItem(R.id.action_home).setVisible(true);
|
||||
nav_Menu.findItem(R.id.action_settings).setVisible(true);
|
||||
nav_Menu.findItem(R.id.action_logout).setVisible(true);
|
||||
nav_Menu.findItem(R.id.action_bookmarks).setVisible(true);
|
||||
nav_Menu.findItem(R.id.action_review).setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void changeDrawerIconToBackButton() {
|
||||
toggle.setDrawerIndicatorEnabled(false);
|
||||
toggle.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white);
|
||||
toggle.setToolbarNavigationClickListener(view -> onBackPressed());
|
||||
}
|
||||
|
||||
public void changeDrawerIconToDefault() {
|
||||
if (toggle != null) {
|
||||
toggle.setDrawerIndicatorEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the username in navigationHeader.
|
||||
*/
|
||||
private void setUserName() {
|
||||
|
||||
View navHeaderView = navigationView.getHeaderView(0);
|
||||
TextView username = navHeaderView.findViewById(R.id.username);
|
||||
AccountManager accountManager = AccountManager.get(this);
|
||||
Account[] allAccounts = accountManager.getAccountsByType(BuildConfig.ACCOUNT_TYPE);
|
||||
if (allAccounts.length != 0) {
|
||||
username.setText(allAccounts[0].name);
|
||||
}
|
||||
LinearLayout userIcon = navHeaderView.findViewById(R.id.user_details);
|
||||
userIcon.setOnClickListener(v -> {
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
ProfileActivity.startYourself(NavigationBaseActivity.this);
|
||||
});
|
||||
}
|
||||
|
||||
public void initBackButton() {
|
||||
int backStackEntryCount = getSupportFragmentManager().getBackStackEntryCount();
|
||||
toggle.setDrawerIndicatorEnabled(backStackEntryCount == 0);
|
||||
toggle.setToolbarNavigationClickListener(v -> onBackPressed());
|
||||
}
|
||||
|
||||
/**
|
||||
* This method changes the toolbar icon to back regardless of any conditions that
|
||||
* there is any fragment in the backStack or not
|
||||
*/
|
||||
public void forceInitBackButton() {
|
||||
toggle.setDrawerIndicatorEnabled(false);
|
||||
toggle.setToolbarNavigationClickListener(v -> onBackPressed());
|
||||
}
|
||||
|
||||
public void initBack() {
|
||||
setSupportActionBar(toolbar);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setDisplayShowHomeEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull final MenuItem item) {
|
||||
final int itemId = item.getItemId();
|
||||
switch (itemId) {
|
||||
case R.id.action_login:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
startActivityWithFlags(
|
||||
this, LoginActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
applicationKvStore.putBoolean("login_skipped", false);
|
||||
finish();
|
||||
return true;
|
||||
case R.id.action_home:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
startActivityWithFlags(
|
||||
this, MainActivity.class, Intent.FLAG_ACTIVITY_CLEAR_TOP,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
return true;
|
||||
case R.id.action_about:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
startActivityWithFlags(this, AboutActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
return true;
|
||||
case R.id.action_settings:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
startActivityWithFlags(this, SettingsActivity.class, Intent.FLAG_ACTIVITY_REORDER_TO_FRONT,
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
return true;
|
||||
case R.id.action_introduction:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
WelcomeActivity.startYourself(this);
|
||||
return true;
|
||||
case R.id.action_feedback:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
|
||||
String technicalInfo = commonsLogSender.getExtraInfo();
|
||||
|
||||
Intent feedbackIntent = new Intent(Intent.ACTION_SENDTO);
|
||||
feedbackIntent.setType("message/rfc822");
|
||||
feedbackIntent.setData(Uri.parse("mailto:"));
|
||||
feedbackIntent.putExtra(Intent.EXTRA_EMAIL,
|
||||
new String[]{CommonsApplication.FEEDBACK_EMAIL});
|
||||
feedbackIntent.putExtra(Intent.EXTRA_SUBJECT,
|
||||
CommonsApplication.FEEDBACK_EMAIL_SUBJECT);
|
||||
feedbackIntent.putExtra(Intent.EXTRA_TEXT, String.format(
|
||||
"\n\n%s\n%s", CommonsApplication.FEEDBACK_EMAIL_TEMPLATE_HEADER, technicalInfo));
|
||||
try {
|
||||
startActivity(feedbackIntent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
Toast.makeText(this, R.string.no_email_client, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return true;
|
||||
case R.id.action_logout:
|
||||
new AlertDialog.Builder(this)
|
||||
.setMessage(R.string.logout_verification)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(R.string.yes, (dialog, which) -> {
|
||||
handleLogout();
|
||||
})
|
||||
.setNegativeButton(R.string.no, (dialog, which) -> dialog.cancel())
|
||||
.show();
|
||||
return true;
|
||||
case R.id.action_explore:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
ExploreActivity.startYourself(this);
|
||||
return true;
|
||||
case R.id.action_bookmarks:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
BookmarksActivity.startYourself(this);
|
||||
return true;
|
||||
|
||||
case R.id.action_review:
|
||||
drawerLayout.closeDrawer(navigationView);
|
||||
ReviewActivity.startYourself(this, getString(R.string.title_activity_review));
|
||||
return true;
|
||||
default:
|
||||
Timber.e("Unknown option [%s] selected from the navigation menu", itemId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Ask the logout client to post the logout api
|
||||
*/
|
||||
private void handleLogout() {
|
||||
if (null == progressDialog) {
|
||||
progressDialog = new ProgressDialog(this);
|
||||
progressDialog.setMessage(getString(R.string.please_wait));
|
||||
}
|
||||
|
||||
progressDialog.show();
|
||||
|
||||
disposable.add(logoutClient.postLogout()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(mwQueryResponse -> {
|
||||
BaseLogoutListener logoutListener = new BaseLogoutListener();
|
||||
CommonsApplication app = (CommonsApplication) getApplication();
|
||||
app.clearApplicationData(this, logoutListener);
|
||||
progressDialog.cancel();
|
||||
},
|
||||
t -> {
|
||||
progressDialog.cancel();
|
||||
Toast.makeText(NavigationBaseActivity.this,
|
||||
t.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
|
||||
Timber.e(t, "Something went wrong with post logout api: %s", t
|
||||
.getLocalizedMessage());
|
||||
}
|
||||
));
|
||||
}
|
||||
|
||||
private class BaseLogoutListener implements CommonsApplication.LogoutListener {
|
||||
@Override
|
||||
public void onLogoutComplete() {
|
||||
Timber.d("Logout complete callback received.");
|
||||
Intent nearbyIntent = new Intent(
|
||||
NavigationBaseActivity.this, LoginActivity.class);
|
||||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
nearbyIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(nearbyIntent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void startActivityWithFlags(Context context, Class<T> cls, int... flags) {
|
||||
Intent intent = new Intent(context, cls);
|
||||
for (int flag: flags) {
|
||||
intent.addFlags(flag);
|
||||
}
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
/* This is a workaround for a known Android bug which is present in some API levels.
|
||||
https://issuetracker.google.com/issues/36986021
|
||||
*/
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
if ((intent.getFlags() | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT) > 0) {
|
||||
isRestoredToTop = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void finish() {
|
||||
super.finish();
|
||||
if (Build.VERSION.SDK_INT == 19 || Build.VERSION.SDK_INT == 24 || Build.VERSION.SDK_INT == 25
|
||||
&& !isTaskRoot() && isRestoredToTop) {
|
||||
// Issue with FLAG_ACTIVITY_REORDER_TO_FRONT,
|
||||
// Reordered activity back press will go to home unexpectly,
|
||||
// Workaround: move reordered activity current task to front when it's finished.
|
||||
ActivityManager tasksManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
|
||||
tasksManager.moveTaskToFront(getTaskId(), ActivityManager.MOVE_TASK_NO_USER_ACTION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handles visibility of navigation base toolbar
|
||||
* @param show : Used to handle visibility of toolbar
|
||||
*/
|
||||
public void setNavigationBaseToolbarVisibility(boolean show){
|
||||
if (show){
|
||||
toolbar.setVisibility(View.VISIBLE);
|
||||
}else {
|
||||
toolbar.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
disposable.clear();
|
||||
if (progressDialog != null && progressDialog.isShowing()) {
|
||||
progressDialog.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue