diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java index e63a070..9874946 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivity.java @@ -1,17 +1,27 @@ package com.nauk.moodl.Activities; +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.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; @@ -26,31 +36,11 @@ import com.nauk.moodl.R; public class HomeActivity extends AppCompatActivity { - private BottomNavigationView bottomNavigationView; - private CustomViewPager viewPager; - - - private BottomNavigationView.OnNavigationItemSelectedListener onNavigationItemSelectedListener - = new BottomNavigationView.OnNavigationItemSelectedListener() { - - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - item.setChecked(true); - switch (item.getItemId()) - { - case R.id.navigation_watchlist: - viewPager.setCurrentItem(0); - break; - case R.id.navigation_currencies_list: - viewPager.setCurrentItem(1); - break; - case R.id.navigation_market_cap: - viewPager.setCurrentItem(2); - break; - } - return false; - } - }; + private DrawerLayout drawerLayout; + private Fragment watchlistFragment; + private Fragment holdingsFragment; + private Fragment marketFragment; + private Fragment currentFragment; @Override protected void onCreate(Bundle savedInstanceState) { @@ -63,43 +53,81 @@ public class HomeActivity extends AppCompatActivity { setContentView(R.layout.activity_currency_summary); - viewPager = findViewById(R.id.viewPager); - final HomeActivityPagerAdapter adapter = new HomeActivityPagerAdapter(getSupportFragmentManager(), 3); + watchlistFragment = new Watchlist(); + holdingsFragment = new Summary(); + marketFragment = new MarketCapitalization(); - viewPager.setAdapter(adapter); - viewPager.setOffscreenPageLimit(2); - viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { + 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); + + showFragment(holdingsFragment); + + navigationView.setCheckedItem(R.id.navigation_currencies_list); + + navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override - public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { - if(!bottomNavigationView.getMenu().getItem(position).isChecked()) + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + + switch (item.getItemId()) { - bottomNavigationView.getMenu().getItem(position).setChecked(true); + case R.id.navigation_watchlist: + showFragment(watchlistFragment); + break; + case R.id.navigation_currencies_list: + showFragment(holdingsFragment); + break; + case R.id.navigation_market_cap: + showFragment(marketFragment); + break; + case R.id.navigation_settings: + Intent settingIntent = new Intent(getApplicationContext(), SettingsActivity.class); + startActivity(settingIntent); + break; } + item.setChecked(true); + drawerLayout.closeDrawers(); - if(position % 2 == 0) - { - ((AppBarLayout) findViewById(R.id.app_bar)).setExpanded(false, true); - } - } - - @Override - public void onPageSelected(int position) { - - } - - @Override - public void onPageScrollStateChanged(int state) { - + return false; } }); //Objects initialization //Layouts setup + } - bottomNavigationView = findViewById(R.id.navigationSummary); - bottomNavigationView.setOnNavigationItemSelectedListener(onNavigationItemSelectedListener); - bottomNavigationView.setSelectedItemId(R.id.navigation_currencies_list); + private void showFragment(Fragment fragment) { + FragmentManager fragmentManager = getSupportFragmentManager(); + + if(currentFragment != null) + { + fragmentManager.beginTransaction() + .hide(currentFragment) + .show(fragment) + .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) + .commit(); + } + else + { + fragmentManager.beginTransaction() + .show(fragment) + .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE) + .commit(); + } + + + + currentFragment = fragment; } @Override diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java index 2280755..b78e53e 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/MarketCapitalization.java @@ -5,6 +5,8 @@ import android.content.Intent; import android.graphics.Color; import android.support.v4.app.Fragment; import android.os.Bundle; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.SwipeRefreshLayout; import android.text.SpannableString; import android.util.Log; @@ -73,13 +75,33 @@ public class MarketCapitalization extends Fragment { setupRefreshLayout(); - setupSettingsButton(); + setupDrawerButton(); updateMarketCap(true); return view; } + private void setupDrawerButton() + { + ImageButton drawerButton = view.findViewById(R.id.drawer_button); + drawerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + DrawerLayout drawerLayout = getActivity().findViewById(R.id.drawer_layout); + + if(drawerLayout.isDrawerOpen(GravityCompat.START)) + { + drawerLayout.closeDrawers(); + } + else + { + drawerLayout.openDrawer(GravityCompat.START); + } + } + }); + } + private void setupRefreshLayout() { refreshLayout = view.findViewById(R.id.swiperefreshmarketcap); @@ -95,19 +117,6 @@ public class MarketCapitalization extends Fragment { ); } - private void setupSettingsButton() - { - ImageButton settingsButton = view.findViewById(R.id.settings_button); - - settingsButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent settingIntent = new Intent(getActivity(), SettingsActivity.class); - startActivity(settingIntent); - } - }); - } - @Override public void onResume() { @@ -263,13 +272,11 @@ public class MarketCapitalization extends Fragment { { case MotionEvent.ACTION_DOWN: refreshLayout.setEnabled(false); - ((CustomViewPager) view.getParent().getParent().getParent().getParent().getParent()).setPagingEnabled(false); break; case MotionEvent.ACTION_MOVE: break; default: refreshLayout.setEnabled(true); - ((CustomViewPager) view.getParent().getParent().getParent().getParent().getParent()).setPagingEnabled(true); break; } diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java index 90442a2..7b5ce1c 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Summary.java @@ -13,6 +13,8 @@ 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; +import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.graphics.Palette; import android.util.Log; @@ -114,15 +116,35 @@ public class Summary extends Fragment { setupAddCurrencyButton(fragmentView); - setupSettingsButton(fragmentView); - updateAll(true); + setupDrawerButton(fragmentView); + generateSplashScreen(); return fragmentView; } + private void setupDrawerButton(View view) + { + ImageButton drawerButton = view.findViewById(R.id.drawer_button); + drawerButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + DrawerLayout drawerLayout = getActivity().findViewById(R.id.drawer_layout); + + if(drawerLayout.isDrawerOpen(GravityCompat.START)) + { + drawerLayout.closeDrawers(); + } + else + { + drawerLayout.openDrawer(GravityCompat.START); + } + } + }); + } + private void initiateUpdateRunnable() { updateRunnable = new Runnable() { @@ -204,20 +226,6 @@ public class Summary extends Fragment { }); } - private void setupSettingsButton(View fragmentView) - { - ImageButton settingsButton = fragmentView.findViewById(R.id.settings_button); - - settingsButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent settingIntent = new Intent(getActivity(), SettingsActivity.class); - startActivity(settingIntent); - } - }); - - } - private void generateSplashScreen() { LinearLayout loadingLayout = new LinearLayout(getActivity()); @@ -291,14 +299,14 @@ public class Summary extends Fragment { private void showErrorSnackbar() { - Snackbar.make(getActivity().findViewById(R.id.snackbar_placer), "Error while updating data", Snackbar.LENGTH_LONG) + /*Snackbar.make(getActivity().findViewById(R.id.snackbar_placer), "Error while updating data", Snackbar.LENGTH_LONG) .setAction("Update", new View.OnClickListener() { @Override public void onClick(View view) { } }) - .show(); + .show();*/ } private void resetCounters() @@ -640,7 +648,7 @@ public class Summary extends Fragment { { private void generateSnackBarError(String error) { - View view = getActivity().findViewById(R.id.snackbar_placer); + /*View view = getActivity().findViewById(R.id.snackbar_placer); switch (error) { @@ -673,7 +681,7 @@ public class Summary extends Fragment { Log.d("moodl", error); updateAll(false); - } + }*/ } @Override diff --git a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java index d711f20..3648cb9 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java +++ b/app/src/main/java/com/nauk/moodl/Activities/HomeActivityFragments/Watchlist.java @@ -3,45 +3,31 @@ package com.nauk.moodl.Activities.HomeActivityFragments; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; -import android.graphics.Color; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffColorFilter; -import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.support.v4.app.Fragment; import android.os.Bundle; +import android.support.v4.view.GravityCompat; +import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.SwipeRefreshLayout; import android.support.v7.graphics.Palette; import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.animation.Animation; import android.widget.Button; import android.widget.ImageButton; -import android.widget.ImageView; import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.TextView; -import com.github.mikephil.charting.charts.LineChart; -import com.github.mikephil.charting.data.Entry; -import com.github.mikephil.charting.data.LineData; -import com.github.mikephil.charting.data.LineDataSet; -import com.nauk.moodl.Activities.CurrencyDetailsActivity; 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; -import com.nauk.moodl.DataManagers.CurrencyData.CurrencyDataChart; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyDetailsList; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyTickerList; -import com.nauk.moodl.DataManagers.DatabaseManager; import com.nauk.moodl.DataManagers.PreferencesManager; import com.nauk.moodl.DataManagers.WatchlistManager; -import com.nauk.moodl.PlaceholderManager; import com.nauk.moodl.R; import org.json.JSONException; @@ -50,16 +36,9 @@ import org.json.JSONObject; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import static com.nauk.moodl.MoodlBox.collapseH; import static com.nauk.moodl.MoodlBox.collapseW; -import static com.nauk.moodl.MoodlBox.expandH; import static com.nauk.moodl.MoodlBox.expandW; -import static com.nauk.moodl.MoodlBox.getVerticalExpandAnimation; -import static com.nauk.moodl.MoodlBox.numberConformer; import static java.lang.Math.abs; /** @@ -117,7 +96,7 @@ public class Watchlist extends Fragment { setupAddWatchlistButton(); - setupSettingsButton(); + setupDrawerButton(); setupEditButton(); @@ -130,13 +109,13 @@ public class Watchlist extends Fragment { editButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + LinearLayout watchlistLayout = Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist); + if(editModeEnabled) { editModeEnabled = false; - LinearLayout watchlistLayout = Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist); - - for(int i = 0; i < ((LinearLayout) Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist)).getChildCount(); i++) + for(int i = 0; i < watchlistLayout.getChildCount(); i++) { View watchlistElement = watchlistLayout.getChildAt(i); @@ -148,9 +127,7 @@ public class Watchlist extends Fragment { { editModeEnabled = true; - LinearLayout watchlistLayout = Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist); - - for(int i = 0; i < ((LinearLayout) Watchlist.this.view.findViewById(R.id.linearLayoutWatchlist)).getChildCount(); i++) + for(int i = 0; i < watchlistLayout.getChildCount(); i++) { View watchlistElement = watchlistLayout.getChildAt(i); @@ -175,14 +152,22 @@ public class Watchlist extends Fragment { }); } - private void setupSettingsButton() + private void setupDrawerButton() { - ImageButton settingsButton = view.findViewById(R.id.settings_button); - settingsButton.setOnClickListener(new View.OnClickListener() { + ImageButton drawerButton = view.findViewById(R.id.drawer_button); + drawerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - Intent settingIntent = new Intent(getActivity(), SettingsActivity.class); - startActivity(settingIntent); + DrawerLayout drawerLayout = getActivity().findViewById(R.id.drawer_layout); + + if(drawerLayout.isDrawerOpen(GravityCompat.START)) + { + drawerLayout.closeDrawers(); + } + else + { + drawerLayout.openDrawer(GravityCompat.START); + } } }); } diff --git a/app/src/main/res/drawable/ic_drawer_white_24dp.xml b/app/src/main/res/drawable/ic_drawer_white_24dp.xml new file mode 100644 index 0000000..cf37e2a --- /dev/null +++ b/app/src/main/res/drawable/ic_drawer_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_mode_edit_white_24dp.xml b/app/src/main/res/drawable/ic_mode_edit_white_24dp.xml index 9aabc58..4341bdc 100644 --- a/app/src/main/res/drawable/ic_mode_edit_white_24dp.xml +++ b/app/src/main/res/drawable/ic_mode_edit_white_24dp.xml @@ -1,6 +1,6 @@ diff --git a/app/src/main/res/layout/activity_currency_summary.xml b/app/src/main/res/layout/activity_currency_summary.xml index 29fd129..e573b44 100644 --- a/app/src/main/res/layout/activity_currency_summary.xml +++ b/app/src/main/res/layout/activity_currency_summary.xml @@ -1,45 +1,23 @@ - - + + + android:layout_gravity="start" + app:menu="@menu/summary_navigation_drawer"/> - - - - - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_marketcap_homeactivity.xml b/app/src/main/res/layout/fragment_marketcap_homeactivity.xml index 76084b3..8ac8838 100644 --- a/app/src/main/res/layout/fragment_marketcap_homeactivity.xml +++ b/app/src/main/res/layout/fragment_marketcap_homeactivity.xml @@ -3,8 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" - android:fitsSystemWindows="true" - android:layout_marginBottom="56dp"> + android:fitsSystemWindows="true"> + + - - diff --git a/app/src/main/res/layout/fragment_summary_homeactivity.xml b/app/src/main/res/layout/fragment_summary_homeactivity.xml index 54fff3c..0094d01 100644 --- a/app/src/main/res/layout/fragment_summary_homeactivity.xml +++ b/app/src/main/res/layout/fragment_summary_homeactivity.xml @@ -53,14 +53,14 @@ android:layout_margin="10dp"> + android:layout_gravity="start|center_vertical" + android:contentDescription="Drawer"/> diff --git a/app/src/main/res/layout/fragment_watchlist_homeactivity.xml b/app/src/main/res/layout/fragment_watchlist_homeactivity.xml index 8cc3c0e..e0f65d6 100644 --- a/app/src/main/res/layout/fragment_watchlist_homeactivity.xml +++ b/app/src/main/res/layout/fragment_watchlist_homeactivity.xml @@ -3,8 +3,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" - android:fitsSystemWindows="true" - android:layout_marginBottom="56dp"> + android:fitsSystemWindows="true"> + android:layout_gravity="start|center_vertical" + android:contentDescription="Drawer"/> + android:layout_gravity="end|center_vertical" + android:contentDescription="Edit mode"/> diff --git a/app/src/main/res/menu/navigation_home.xml b/app/src/main/res/menu/navigation_home.xml deleted file mode 100644 index c53ff47..0000000 --- a/app/src/main/res/menu/navigation_home.xml +++ /dev/null @@ -1,19 +0,0 @@ - - - - - - - - - - diff --git a/app/src/main/res/menu/summary_navigation_drawer.xml b/app/src/main/res/menu/summary_navigation_drawer.xml new file mode 100644 index 0000000..6d90c1e --- /dev/null +++ b/app/src/main/res/menu/summary_navigation_drawer.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + +