Commit a2b96df9 authored by Thomas's avatar Thomas
Browse files

Improves navigation with tabs in top bar

parent 40dfff7b
......@@ -5,17 +5,22 @@ The number of libraries is minimized and it does not use tracking tools. The sou
### Features
**Multi-accounts management**
* Add accounts from different instances
* Switch from one account to another by a simple click
**Timelines**
* Federated / Local / Home
* Switch from one timeline to another by using the menu or by swiping the screen.
* Clicks on toots display the related conversations (context)
* Clicks on mentioned accounts display details about these accounts
* Clicks on hashtags display toots containing this hashtags
**Actions on toots**
* Mute an account related to a toot
* Block an account related to a toot
* Report inappropriate toots to administrators
......@@ -25,7 +30,9 @@ The number of libraries is minimized and it does not use tracking tools. The sou
* Download media
* Translation of toots by a simple click (via the Yandex API)
**Write a toot**
* Add media
* Change the visibility of the toot
* Mention accounts in toots with autocompletion (@ + 2 characters)
......@@ -34,27 +41,38 @@ The number of libraries is minimized and it does not use tracking tools. The sou
* Toots which have not been sent are saved (drafts) - can be disabled in settings
* Drafts can be edited/deleted/scheduled
**Scheduled toots**
* Can be edited/deleted/scheduled at another date as long as they have not been sent.
**Interaction with accounts**
* Follow/Unfollow/Block/Unblock/Mute/Unmute
* Display details of accounts
* Authorize/Reject follow requests (for locked accounts)
**Searches**
* A top bar allows to make researches for accounts/tags/toots
* A click on a tag displays toots containing this tag
**Network optimization**
* Load of media: Automatic/WIFI only/Ask
* Customization of the number of toots/accounts per load
**Notifications**
* Notifications for new toots on the home page (could be disabled in settings)
* Notifications for new events (could be disabled or filtered in settings)
**Built-in browser**
* Full screen videos
* Disable JavaScript (default: enabled)
* Disable third-party cookies (default: disabled)
......
......@@ -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;
......@@ -54,6 +55,7 @@ import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer;
import java.io.File;
import java.util.HashMap;
import java.util.Locale;
import java.util.Stack;
import fr.gouv.etalab.mastodon.asynctasks.UpdateAccountInfoByIDAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.Account;
......@@ -76,6 +78,7 @@ 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;
import static fr.gouv.etalab.mastodon.helper.Helper.PREF_KEY_ID;
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;
......@@ -99,6 +102,10 @@ public class MainActivity extends AppCompatActivity
private TabLayout tabLayout;
private ViewPager viewPager;
private RelativeLayout main_app_container;
private Stack<Integer> stackBack = new Stack<>();
public MainActivity() {
}
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -106,7 +113,7 @@ public class MainActivity extends AppCompatActivity
SharedPreferences sharedpreferences = getSharedPreferences(Helper.APP_PREFS, android.content.Context.MODE_PRIVATE);
int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
final int theme = sharedpreferences.getInt(Helper.SET_THEME, Helper.THEME_DARK);
if( theme == Helper.THEME_LIGHT){
setTheme(R.style.AppTheme_NoActionBar);
}else {
......@@ -122,6 +129,17 @@ public class MainActivity extends AppCompatActivity
finish();
return;
}
if( theme == Helper.THEME_DARK){
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_home_tl,R.color.dark_text);
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_users_tl,R.color.dark_text);
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_globe_tl,R.color.dark_text);
changeDrawableColor(getApplicationContext(), R.drawable.ic_notifications_tl,R.color.dark_text);
}else {
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_home_tl,R.color.black);
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_users_tl,R.color.black);
changeDrawableColor(getApplicationContext(), R.drawable.ic_action_globe_tl,R.color.black);
changeDrawableColor(getApplicationContext(), R.drawable.ic_notifications_tl,R.color.black);
}
Helper.fillMapEmoji(getApplicationContext());
//Here, the user is authenticated
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
......@@ -139,6 +157,14 @@ public class MainActivity extends AppCompatActivity
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
if (stackBack.empty())
stackBack.push(0);
if (stackBack.contains(tab.getPosition())) {
stackBack.remove(stackBack.indexOf(tab.getPosition()));
stackBack.push(tab.getPosition());
} else {
stackBack.push(tab.getPosition());
}
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
MenuItem item = null;
String fragmentTag = null;
......@@ -169,6 +195,10 @@ public class MainActivity extends AppCompatActivity
unCheckAllMenuItems(navigationView.getMenu());
item.setChecked(true);
}
if( tab.getPosition() < 3 )
toot.setVisibility(View.VISIBLE);
else
toot.setVisibility(View.GONE);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}
......@@ -180,6 +210,17 @@ public class MainActivity extends AppCompatActivity
@Override
public void onTabReselected(TabLayout.Tab tab) {
if( viewPager.getVisibility() == View.GONE){
viewPager.setVisibility(View.VISIBLE);
tabLayout.setVisibility(View.VISIBLE);
main_app_container.setVisibility(View.GONE);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
}
if( tab.getPosition() <3 )
toot.setVisibility(View.VISIBLE);
else
toot.setVisibility(View.GONE);
}
});
......@@ -188,7 +229,6 @@ public class MainActivity extends AppCompatActivity
toolbar_search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
toot.setVisibility(View.VISIBLE);
//Hide keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(toolbar_search.getWindowToken(), 0);
......@@ -203,24 +243,8 @@ public class MainActivity extends AppCompatActivity
}
});
//Hide/Close the searchview
/*toolbar_search.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( toolbarTitle.getVisibility() == View.VISIBLE)
toolbarTitle.setVisibility(View.GONE);
if( pp_actionBar.getVisibility() == View.VISIBLE)
pp_actionBar.setVisibility(View.GONE);
}
});*/
toolbar_search.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if( hasFocus){
toolbarTitle.setVisibility(View.GONE);
pp_actionBar.setVisibility(View.GONE);
}
}
});
toolbar_search.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
......@@ -230,6 +254,18 @@ public class MainActivity extends AppCompatActivity
return false;
}
});
toolbar_search.setOnSearchClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if( toolbar_search.isIconified()){
toolbarTitle.setVisibility(View.VISIBLE);
pp_actionBar.setVisibility(View.VISIBLE);
}else {
toolbarTitle.setVisibility(View.GONE);
pp_actionBar.setVisibility(View.GONE);
}
}
});
//Hide the default title
if( getSupportActionBar() != null)
......@@ -296,44 +332,8 @@ public class MainActivity extends AppCompatActivity
if (savedInstanceState == null && !matchingIntent) {
navigationView.setCheckedItem(R.id.nav_home);
navigationView.getMenu().performIdentifierAction(R.id.nav_home, 0);
toolbarTitle.setText(R.string.home_menu);
}
//Title and menu selection when back pressed
getSupportFragmentManager().addOnBackStackChangedListener(
new FragmentManager.OnBackStackChangedListener() {
public void onBackStackChanged() {
FragmentManager fm = getSupportFragmentManager();
if( fm != null && fm.getBackStackEntryCount() > 0) {
String fragmentTag = fm.getBackStackEntryAt(fm.getBackStackEntryCount() - 1).getName();
if( fragmentTag != null) {
if( tagTile.get(fragmentTag) != null)
toolbarTitle.setText(tagTile.get(fragmentTag));
if( tagItem.get(fragmentTag) != null) {
unCheckAllMenuItems(navigationView.getMenu());
if( navigationView.getMenu().findItem(tagItem.get(fragmentTag)) != null)
navigationView.getMenu().findItem(tagItem.get(fragmentTag)).setChecked(true);
}
if( fragmentTag.equals("HOME_TIMELINE") || fragmentTag.equals("LOCAL_TIMELINE") || fragmentTag.equals("PUBLIC_TIMELINE") || fragmentTag.equals("NOTIFICATIONS")){
main_app_container.setVisibility(View.GONE);
viewPager.setVisibility(View.VISIBLE);
tabLayout.setVisibility(View.VISIBLE);
}else {
main_app_container.setVisibility(View.VISIBLE);
viewPager.setVisibility(View.GONE);
tabLayout.setVisibility(View.GONE);
}
//selectTabBar(fragmentTag);
if( fragmentTag.equals("HOME_TIMELINE") || fragmentTag.equals("LOCAL_TIMELINE") || fragmentTag.equals("PUBLIC_TIMELINE") || fragmentTag.equals("SCHEDULED")){
toot.setVisibility(View.VISIBLE);
}else {
toot.setVisibility(View.GONE);
}
}
}
}
});
}
private void unCheckAllMenuItems(@NonNull final Menu menu) {
......@@ -422,7 +422,40 @@ public class MainActivity extends AppCompatActivity
if( !toolbar_search.isIconified()){
toolbar_search.setIconified(true);
}
super.onBackPressed();
if( viewPager.getVisibility() == View.VISIBLE){
if (stackBack.size() > 1) {
stackBack.pop();
viewPager.setCurrentItem(stackBack.lastElement());
}else {
super.onBackPressed();
}
}else {
viewPager.setVisibility(View.VISIBLE);
tabLayout.setVisibility(View.VISIBLE);
main_app_container.setVisibility(View.GONE);
final NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
unCheckAllMenuItems(navigationView.getMenu());
toot.setVisibility(View.VISIBLE);
switch (viewPager.getCurrentItem()){
case 0:
toolbarTitle.setText(R.string.home_menu);
navigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
break;
case 1:
toolbarTitle.setText(R.string.local_menu);
navigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
break;
case 2:
toolbarTitle.setText(R.string.global_menu);
navigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
break;
case 3:
toolbarTitle.setText(R.string.notifications);
navigationView.getMenu().findItem(R.id.nav_home).setChecked(true);
break;
}
}
}
}
......@@ -549,7 +582,7 @@ public class MainActivity extends AppCompatActivity
TabLayoutSettingsFragment tabLayoutSettingsFragment= new TabLayoutSettingsFragment();
fragmentTag = "TABLAYOUT_SETTINGS";
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, tabLayoutSettingsFragment, fragmentTag).addToBackStack(fragmentTag).commit();
.replace(R.id.main_app_container, tabLayoutSettingsFragment, fragmentTag).commit();
} else if (id == R.id.nav_favorites) {
toot.setVisibility(View.GONE);
......@@ -558,7 +591,7 @@ public class MainActivity extends AppCompatActivity
statusFragment.setArguments(bundle);
fragmentTag = "FAVOURITES";
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, statusFragment, fragmentTag).addToBackStack(fragmentTag).commit();
.replace(R.id.main_app_container, statusFragment, fragmentTag).commit();
} else if (id == R.id.nav_blocked) {
toot.setVisibility(View.GONE);
accountsFragment = new DisplayAccountsFragment();
......@@ -566,7 +599,7 @@ public class MainActivity extends AppCompatActivity
accountsFragment.setArguments(bundle);
fragmentTag = "BLOCKS";
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, accountsFragment, fragmentTag).addToBackStack(fragmentTag).commit();
.replace(R.id.main_app_container, accountsFragment, fragmentTag).commit();
}else if (id == R.id.nav_muted) {
toot.setVisibility(View.GONE);
accountsFragment = new DisplayAccountsFragment();
......@@ -574,19 +607,19 @@ public class MainActivity extends AppCompatActivity
accountsFragment.setArguments(bundle);
fragmentTag = "MUTED";
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, accountsFragment, fragmentTag).addToBackStack(fragmentTag).commit();
.replace(R.id.main_app_container, accountsFragment, fragmentTag).commit();
}else if (id == R.id.nav_scheduled) {
toot.setVisibility(View.VISIBLE);
DisplayScheduledTootsFragment displayScheduledTootsFragment = new DisplayScheduledTootsFragment();
fragmentTag = "SCHEDULED";
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, displayScheduledTootsFragment, fragmentTag).addToBackStack(fragmentTag).commit();
.replace(R.id.main_app_container, displayScheduledTootsFragment, fragmentTag).commit();
}else if( id == R.id.nav_follow_request){
toot.setVisibility(View.GONE);
DisplayFollowRequestSentFragment followRequestSentFragment = new DisplayFollowRequestSentFragment();
fragmentTag = "FOLLOW_REQUEST_SENT";
fragmentManager.beginTransaction()
.replace(R.id.main_app_container, followRequestSentFragment, fragmentTag).addToBackStack(fragmentTag).commit();
.replace(R.id.main_app_container, followRequestSentFragment, fragmentTag).commit();
}
//selectTabBar(fragmentTag);
toolbarTitle.setText(item.getTitle());
......@@ -653,27 +686,25 @@ public class MainActivity extends AppCompatActivity
//Selection comes from another menu, no action to do
DisplayStatusFragment statusFragment;
Bundle bundle = new Bundle();
toot.setVisibility(View.VISIBLE);
switch (position) {
case 0:
toot.setVisibility(View.VISIBLE);
statusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.HOME);
statusFragment.setArguments(bundle);
return statusFragment;
case 1:
toot.setVisibility(View.VISIBLE);
statusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.LOCAL);
statusFragment.setArguments(bundle);
return statusFragment;
case 2:
toot.setVisibility(View.VISIBLE);
statusFragment = new DisplayStatusFragment();
bundle.putSerializable("type", RetrieveFeedsAsyncTask.Type.PUBLIC);
statusFragment.setArguments(bundle);
return statusFragment;
case 3:
toot.setVisibility(View.GONE);
return new DisplayNotificationsFragment();
}
......
......@@ -24,13 +24,18 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.LocalBroadcastManager;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.Html;
import android.text.TextWatcher;
......@@ -57,7 +62,9 @@ import android.widget.Toast;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import java.io.FileNotFoundException;
import java.io.InputStream;
......@@ -94,6 +101,7 @@ import fr.gouv.etalab.mastodon.sqlite.Sqlite;
import mastodon.etalab.gouv.fr.mastodon.R;
import static fr.gouv.etalab.mastodon.helper.Helper.changeDrawableColor;
import static fr.gouv.etalab.mastodon.helper.Helper.loadPPInActionBar;
/**
* Created by Thomas on 01/05/2017.
......@@ -203,6 +211,27 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
}else {
setTitle(R.string.toot_title);
}
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
Account account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
ImageLoader imageLoader;
DisplayImageOptions options = new DisplayImageOptions.Builder().displayer(new SimpleBitmapDisplayer()).cacheInMemory(false)
.cacheOnDisk(true).resetViewBeforeLoading(true).build();
imageLoader = ImageLoader.getInstance();
imageLoader.loadImage(account.getAvatar(), options, new SimpleImageLoadingListener(){
@Override
public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
super.onLoadingComplete(imageUri, view, loadedImage);
if( getSupportActionBar() != null){
BitmapDrawable ppDrawable = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(loadedImage, (int) Helper.convertDpToPixel(25, getApplicationContext()), (int) Helper.convertDpToPixel(25, getApplicationContext()), true));
getSupportActionBar().setIcon(ppDrawable);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
}
@Override
public void onLoadingFailed(java.lang.String imageUri, android.view.View view, FailReason failReason){
}});
if( sharedContent != null ){ //Shared content
if( sharedSubject != null){
......@@ -238,9 +267,7 @@ public class TootActivity extends AppCompatActivity implements OnRetrieveSearcAc
LocalBroadcastManager.getInstance(this).registerReceiver(search_validate, new IntentFilter(Helper.SEARCH_VALIDATE_ACCOUNT));
FloatingActionButton toot_close_accounts = (FloatingActionButton) findViewById(R.id.toot_close_accounts);
SQLiteDatabase db = Sqlite.getInstance(getApplicationContext(), Sqlite.DB_NAME, null, Sqlite.DB_VERSION).open();
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
Account account = new AccountDAO(getApplicationContext(),db).getAccountByID(userId);
boolean isAccountPrivate = account.isLocked();
FloatingActionButton ic_close = (FloatingActionButton) findViewById(R.id.toot_close_reply);
......
......@@ -109,6 +109,7 @@ import fr.gouv.etalab.mastodon.activities.HashTagActivity;
import fr.gouv.etalab.mastodon.activities.LoginActivity;
import fr.gouv.etalab.mastodon.activities.MainActivity;
import fr.gouv.etalab.mastodon.activities.ShowAccountActivity;
import fr.gouv.etalab.mastodon.activities.TootActivity;
import fr.gouv.etalab.mastodon.activities.WebviewActivity;
import fr.gouv.etalab.mastodon.asynctasks.RemoveAccountAsyncTask;
import fr.gouv.etalab.mastodon.client.Entities.Account;
......@@ -896,7 +897,7 @@ public class Helper {
ppDrawable = new BitmapDrawable(activity.getResources(), Bitmap.createScaledBitmap(loadedImage, (int) convertDpToPixel(25, activity), (int) convertDpToPixel(25, activity), true));
toolBar.findViewById(R.id.pp_actionBar).setBackgroundDrawable(ppDrawable);
}else{
ActionBar supportActionBar = ((MainActivity) activity).getSupportActionBar();
ActionBar supportActionBar = ((TootActivity) activity).getSupportActionBar();
if( supportActionBar != null){
ppDrawable = new BitmapDrawable(activity.getResources(), Bitmap.createScaledBitmap(loadedImage, (int) convertDpToPixel(20, activity), (int) convertDpToPixel(20, activity), true));
supportActionBar.setIcon(ppDrawable);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment