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"?>
<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">
<option name="myDefaultNullable" value="android.support.annotation.Nullable" />
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />

View File

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

View File

@ -10,7 +10,6 @@ import android.os.Handler;
import android.os.Looper;
import android.support.annotation.NonNull;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.os.Bundle;
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.HomeActivity;
import com.nauk.moodl.Activities.SettingsActivity;
import com.nauk.moodl.DataManagers.BalanceManager;
import com.nauk.moodl.DataManagers.CurrencyData.Currency;
import com.nauk.moodl.DataManagers.CurrencyData.CurrencyCardview;

View File

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

View File

@ -5,12 +5,36 @@
android:background="@drawable/gradient_background"
android:padding="16dp"
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="Moodl"
android:textStyle="bold"/>
android:text="@string/app_name"
android:textStyle="bold"
android:layout_gravity="center"
android:textColor="@color/white"
android:textSize="24sp"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/totalValueDrawer"
android:textColor="@color/white"
android:textSize="20sp"/>
</LinearLayout>

View File

@ -17,10 +17,18 @@
android:icon="@drawable/ic_pie_chart_black_24dp"
android:title="@string/title_market_cap" />
</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>