Drawer improvement

- Rework fragment loading
- Add drawer header
- Add sub category for settings (more to come)
- Rework watchlist update with asynchronous work
This commit is contained in:
Tanguy Herbron 2018-05-23 11:08:30 +02:00
parent 5e2c2668db
commit bdc36f149f
7 changed files with 109 additions and 59 deletions

Binary file not shown.

5
.idea/misc.xml generated
View File

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="EntryPointsManager">
<list size="1">
<item index="0" class="java.lang.String" itemvalue="org.greenrobot.eventbus.Subscribe" />
</list>
</component>
<component name="NullableNotNullManager"> <component name="NullableNotNullManager">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" /> <option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" /> <option name="myDefaultNotNull" value="android.support.annotation.NonNull" />

View File

@ -4,26 +4,21 @@ import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.NavigationView; import android.support.design.widget.NavigationView;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.Window; import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import com.nauk.moodl.Activities.DetailsActivityFragments.Home;
import com.nauk.moodl.Activities.HomeActivityFragments.MarketCapitalization; import com.nauk.moodl.Activities.HomeActivityFragments.MarketCapitalization;
import com.nauk.moodl.Activities.HomeActivityFragments.Summary; import com.nauk.moodl.Activities.HomeActivityFragments.Summary;
import com.nauk.moodl.Activities.HomeActivityFragments.Watchlist; import com.nauk.moodl.Activities.HomeActivityFragments.Watchlist;
import com.nauk.moodl.HomeActivityPagerAdapter;
import com.nauk.moodl.LayoutManagers.CustomViewPager;
import com.nauk.moodl.R; import com.nauk.moodl.R;
//Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart //Use WilliamChart for charts https://github.com/diogobernardino/WilliamChart
@ -57,16 +52,6 @@ public class HomeActivity extends AppCompatActivity {
holdingsFragment = new Summary(); holdingsFragment = new Summary();
marketFragment = new MarketCapitalization(); marketFragment = new MarketCapitalization();
getSupportFragmentManager().beginTransaction()
.add(R.id.content_frame, watchlistFragment)
.addToBackStack(null)
.add(R.id.content_frame, marketFragment)
.addToBackStack(null)
.add(R.id.content_frame, holdingsFragment)
.addToBackStack(null)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
drawerLayout = findViewById(R.id.drawer_layout); drawerLayout = findViewById(R.id.drawer_layout);
NavigationView navigationView = findViewById(R.id.nav_view); NavigationView navigationView = findViewById(R.id.nav_view);
@ -78,6 +63,8 @@ public class HomeActivity extends AppCompatActivity {
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
item.setChecked(true);
switch (item.getItemId()) switch (item.getItemId())
{ {
case R.id.navigation_watchlist: case R.id.navigation_watchlist:
@ -92,9 +79,10 @@ public class HomeActivity extends AppCompatActivity {
case R.id.navigation_settings: case R.id.navigation_settings:
Intent settingIntent = new Intent(getApplicationContext(), SettingsActivity.class); Intent settingIntent = new Intent(getApplicationContext(), SettingsActivity.class);
startActivity(settingIntent); startActivity(settingIntent);
item.setChecked(false);
break; break;
} }
item.setChecked(true);
drawerLayout.closeDrawers(); drawerLayout.closeDrawers();
return false; return false;
@ -108,24 +96,24 @@ public class HomeActivity extends AppCompatActivity {
private void showFragment(Fragment fragment) { private void showFragment(Fragment fragment) {
FragmentManager fragmentManager = getSupportFragmentManager(); FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
if(currentFragment != null) if(currentFragment != null)
{ {
fragmentManager.beginTransaction() fragmentTransaction.hide(currentFragment);
.hide(currentFragment) }
.show(fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) if(fragment.isAdded())
.commit(); {
fragmentTransaction.show(fragment);
} }
else else
{ {
fragmentManager.beginTransaction() fragmentTransaction.add(R.id.content_frame, fragment).addToBackStack(null);
.show(fragment)
.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
} }
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
.commit();
currentFragment = fragment; currentFragment = fragment;
} }
@ -152,9 +140,8 @@ public class HomeActivity extends AppCompatActivity {
switch (id) switch (id)
{ {
/*case R.id.action_settings: case R.id.navigation_settings:
Log.d(this.getResources().getString(R.string.debug), "Setting button toggled"); break;
break;*/
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);

View File

@ -10,7 +10,6 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.CollapsingToolbarLayout; import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
@ -30,7 +29,6 @@ import android.widget.TextView;
import com.nauk.moodl.Activities.CurrencySelectionActivity; import com.nauk.moodl.Activities.CurrencySelectionActivity;
import com.nauk.moodl.Activities.HomeActivity; import com.nauk.moodl.Activities.HomeActivity;
import com.nauk.moodl.Activities.SettingsActivity;
import com.nauk.moodl.DataManagers.BalanceManager; import com.nauk.moodl.DataManagers.BalanceManager;
import com.nauk.moodl.DataManagers.CurrencyData.Currency; import com.nauk.moodl.DataManagers.CurrencyData.Currency;
import com.nauk.moodl.DataManagers.CurrencyData.CurrencyCardview; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyCardview;

View File

@ -4,6 +4,7 @@ import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
@ -61,7 +62,7 @@ public class Watchlist extends Fragment {
private boolean editModeEnabled; private boolean editModeEnabled;
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{ {
view = inflater.inflate(R.layout.fragment_watchlist_homeactivity, container, false); view = inflater.inflate(R.layout.fragment_watchlist_homeactivity, container, false);
@ -73,13 +74,7 @@ public class Watchlist extends Fragment {
defaultCurrency = preferencesManager.getDefaultCurrency(); defaultCurrency = preferencesManager.getDefaultCurrency();
currencyTickerList = new CurrencyTickerList(getActivity()); currencyTickerList = new CurrencyTickerList(getActivity());
tickerUpdated = false; tickerUpdated = false;
currencyTickerList.update(new BalanceManager.IconCallBack() { updateTickerList();
@Override
public void onSuccess() {
tickerUpdated = true;
checkUpdatedData();
}
});
editModeEnabled = false; editModeEnabled = false;
@ -103,6 +98,25 @@ public class Watchlist extends Fragment {
return view; return view;
} }
private void updateTickerList()
{
AsyncTask<Void, Integer, Void> updater = new AsyncTask<Void, Integer, Void>() {
@Override
protected Void doInBackground(Void... voids) {
currencyTickerList.update(new BalanceManager.IconCallBack() {
@Override
public void onSuccess() {
tickerUpdated = true;
checkUpdatedData();
}
});
return null;
}
};
updater.execute();
}
private void setupEditButton() private void setupEditButton()
{ {
ImageButton editButton = view.findViewById(R.id.edit_button); ImageButton editButton = view.findViewById(R.id.edit_button);
@ -119,8 +133,11 @@ public class Watchlist extends Fragment {
{ {
View watchlistElement = watchlistLayout.getChildAt(i); View watchlistElement = watchlistLayout.getChildAt(i);
watchlistElement.setClickable(true); if(watchlistElement instanceof LinearLayout)
collapseW(watchlistElement.findViewById(R.id.deleteCardWatchlist)); {
watchlistElement.setClickable(true);
collapseW(watchlistElement.findViewById(R.id.deleteCardWatchlist));
}
} }
} }
else else
@ -131,8 +148,11 @@ public class Watchlist extends Fragment {
{ {
View watchlistElement = watchlistLayout.getChildAt(i); View watchlistElement = watchlistLayout.getChildAt(i);
watchlistElement.setClickable(false); if(watchlistElement instanceof LinearLayout)
expandW(watchlistElement.findViewById(R.id.deleteCardWatchlist)); {
watchlistElement.setClickable(false);
expandW(watchlistElement.findViewById(R.id.deleteCardWatchlist));
}
} }
} }
} }
@ -200,15 +220,23 @@ public class Watchlist extends Fragment {
lastTimestamp = System.currentTimeMillis()/1000; lastTimestamp = System.currentTimeMillis()/1000;
detailsUpdated = false; detailsUpdated = false;
watchlistManager.updateWatchlist(); AsyncTask<Void, Integer, Void> watchlistUpdater = new AsyncTask<Void, Integer, Void>() {
currencyDetailsList.update(new BalanceManager.IconCallBack() {
@Override @Override
public void onSuccess() { protected Void doInBackground(Void... voids) {
detailsUpdated = true; watchlistManager.updateWatchlist();
checkUpdatedData();
currencyDetailsList.update(new BalanceManager.IconCallBack() {
@Override
public void onSuccess() {
detailsUpdated = true;
checkUpdatedData();
}
});
return null;
} }
}); };
watchlistUpdater.execute();
} }
else else
{ {

View File

@ -5,12 +5,36 @@
android:background="@drawable/gradient_background" android:background="@drawable/gradient_background"
android:padding="16dp" android:padding="16dp"
android:orientation="vertical" android:orientation="vertical"
android:gravity="bottom"> android:gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher_moodl"
android:layout_marginRight="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textStyle="bold"
android:layout_gravity="center"
android:textColor="@color/white"
android:textSize="24sp"/>
</LinearLayout>
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="Moodl" android:id="@+id/totalValueDrawer"
android:textStyle="bold"/> android:textColor="@color/white"
android:textSize="20sp"/>
</LinearLayout> </LinearLayout>

View File

@ -17,10 +17,18 @@
android:icon="@drawable/ic_pie_chart_black_24dp" android:icon="@drawable/ic_pie_chart_black_24dp"
android:title="@string/title_market_cap" /> android:title="@string/title_market_cap" />
<item
android:id="@+id/navigation_settings"
android:icon="@drawable/ic_settings_black_24dp"
android:title="@string/title_activity_settings" />
</group> </group>
<item android:title="Other">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/navigation_settings"
android:icon="@drawable/ic_settings_black_24dp"
android:title="@string/title_activity_settings" />
</group>
</menu>
</item>
</menu> </menu>