Start using material design viewpager

This commit is contained in:
Phillip Thelen 2015-06-29 16:04:03 +02:00
parent 549281b969
commit ef177cef0f
16 changed files with 437 additions and 1370 deletions

View file

@ -27,7 +27,7 @@
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden|adjustResize">
android:windowSoftInputMode="stateHidden|adjustResize">:D
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -69,12 +69,6 @@
android:name="io.fabric.ApiKey"
android:value="2eb3b3edb3b0f4722d37d649a5af366656e46ddd" />
<activity
android:name=".MainActivityNew"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden|adjustResize"
android:theme="@style/CustomTheme" />
<activity android:name=".AboutActivity" />
</application>

View file

@ -108,52 +108,52 @@
</content>
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="design-22.2.0" level="project" />
<orderEntry type="library" exported="" name="aboutlibraries-5.0.5" level="project" />
<orderEntry type="library" exported="" name="instabugsupport-1.4" level="project" />
<orderEntry type="library" exported="" name="kotlin-runtime-0.11.91" level="project" />
<orderEntry type="library" exported="" name="org.abego.treelayout.core-1.0.1" level="project" />
<orderEntry type="library" exported="" name="library-2.1.4" level="project" />
<orderEntry type="library" exported="" name="picasso-2.5.2" level="project" />
<orderEntry type="library" exported="" name="paperboy-0d4e14bbb5" level="project" />
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
<orderEntry type="library" exported="" name="retrofit-1.6.0" level="project" />
<orderEntry type="library" exported="" name="kenburnsview-1.0.6" level="project" />
<orderEntry type="library" exported="" name="library-1.0.16" level="project" />
<orderEntry type="library" exported="" name="adapters-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="mimecraft-1.1.1" level="project" />
<orderEntry type="library" exported="" name="antlr4-runtime-4.4" level="project" />
<orderEntry type="library" exported="" name="antlr4-annotations-4.4" level="project" />
<orderEntry type="library" exported="" name="materialviewpager-1.0.5" level="project" />
<orderEntry type="library" exported="" name="fabric-1.3.1" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="android-observablescrollview-1.5.2" level="project" />
<orderEntry type="library" exported="" name="antlr4-4.4" level="project" />
<orderEntry type="library" exported="" name="gson-2.2.4" level="project" />
<orderEntry type="library" exported="" name="crashlytics-core-2.3.0" level="project" />
<orderEntry type="library" exported="" name="antlr-runtime-3.5.2" level="project" />
<orderEntry type="library" exported="" name="materialdrawer-3.0.8" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="gridlayout-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="kotlin-stdlib-0.11.91" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="baseLibrary-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="butterknife-6.1.0" level="project" />
<orderEntry type="library" exported="" name="commons-lang3-3.3.2" level="project" />
<orderEntry type="library" exported="" name="beta-1.1.2" level="project" />
<orderEntry type="library" exported="" name="crouton-1.8.1" level="project" />
<orderEntry type="library" exported="" name="iconics-1.1.0" level="project" />
<orderEntry type="library" exported="" name="guava-17.0" level="project" />
<orderEntry type="library" exported="" name="instabugcore-1.4" level="project" />
<orderEntry type="library" exported="" name="library-1.1.0" level="project" />
<orderEntry type="library" exported="" name="answers-1.2.0" level="project" />
<orderEntry type="library" exported="" name="commons-codec-1.10" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="compiler-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="library-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="crashlytics-2.3.0" level="project" />
<orderEntry type="library" exported="" name="ST4-4.0.8" level="project" />
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="picasso-2.5.2" level="project" />
<orderEntry type="library" exported="" name="library-1.0.16" level="project" />
<orderEntry type="library" exported="" name="kenburnsview-1.0.6" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
<orderEntry type="library" exported="" name="retrofit-1.6.0" level="project" />
<orderEntry type="library" exported="" name="paperboy-0d4e14bbb5" level="project" />
<orderEntry type="library" exported="" name="antlr4-4.4" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="materialdrawer-3.0.8" level="project" />
<orderEntry type="library" exported="" name="crashlytics-core-2.3.0" level="project" />
<orderEntry type="library" exported="" name="aboutlibraries-5.0.5" level="project" />
<orderEntry type="library" exported="" name="library-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="instabugsupport-1.4" level="project" />
<orderEntry type="library" exported="" name="antlr-runtime-3.5.2" level="project" />
<orderEntry type="library" exported="" name="antlr4-annotations-4.4" level="project" />
<orderEntry type="library" exported="" name="butterknife-6.1.0" level="project" />
<orderEntry type="library" exported="" name="org.abego.treelayout.core-1.0.1" level="project" />
<orderEntry type="library" exported="" name="library-1.1.0" level="project" />
<orderEntry type="library" exported="" name="adapters-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="mimecraft-1.1.1" level="project" />
<orderEntry type="library" exported="" name="library-2.1.4" level="project" />
<orderEntry type="library" exported="" name="iconics-1.1.0" level="project" />
<orderEntry type="library" exported="" name="instabugcore-1.4" level="project" />
<orderEntry type="library" exported="" name="android-observablescrollview-1.5.2" level="project" />
<orderEntry type="library" exported="" name="kotlin-stdlib-0.11.91" level="project" />
<orderEntry type="library" exported="" name="support-v4-22.2.0" level="project" />
<orderEntry type="library" exported="" name="crouton-1.8.1" level="project" />
<orderEntry type="library" exported="" name="antlr4-runtime-4.4" level="project" />
<orderEntry type="library" exported="" name="guava-17.0" level="project" />
<orderEntry type="library" exported="" name="crashlytics-2.3.0" level="project" />
<orderEntry type="library" exported="" name="materialviewpager-1.0.5" level="project" />
<orderEntry type="library" exported="" name="baseLibrary-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="fabric-1.3.1" level="project" />
<orderEntry type="library" exported="" name="compiler-1.0-rc0" level="project" />
<orderEntry type="library" exported="" name="beta-1.1.2" level="project" />
<orderEntry type="library" exported="" name="gridlayout-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="ST4-4.0.8" level="project" />
<orderEntry type="library" exported="" name="commons-codec-1.10" level="project" />
<orderEntry type="library" exported="" name="commons-lang3-3.3.2" level="project" />
<orderEntry type="library" exported="" name="kotlin-runtime-0.11.91" level="project" />
<orderEntry type="library" exported="" name="design-22.2.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-22.2.0" level="project" />
</component>
</module>

View file

@ -1,97 +0,0 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:layout_gravity="bottom"
android:orientation="vertical"
android:paddingRight="8dip"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_marginBottom="0dip"
android:layout_marginTop="@dimen/activity_vertical_margin"
>
<include layout="@layout/avatar_with_bars"
android:id="@+id/avatar_with_bars"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:gravity="center"
android:orientation="vertical"
android:paddingTop="@dimen/bar_padding"
android:paddingBottom="@dimen/bar_padding"/>
<ProgressBar
android:id="@+id/PB_AsyncTask"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/Widget.ProgressBar.Horizontal"
android:indeterminate="true"
android:layout_marginBottom="@dimen/PB_marginBottom"
/>
<RelativeLayout
android:id="@+id/RL_addTask"
android:layout_width="match_parent"
android:layout_height="@dimen/new_task_bar_size"
android:layout_gravity="end"
android:background="@drawable/bottom_bar_bg"
android:gravity="bottom"
android:orientation="horizontal"
android:paddingBottom="0dp" >
<ImageButton
android:id="@+id/BT_task_new"
android:layout_width="@dimen/new_task_bat_btn_width"
android:layout_height="match_parent"
android:layout_gravity="top"
android:background="@drawable/selectable_background_cardbank"
android:padding="@dimen/new_task_bat_btn_padding"
android:src="@drawable/ic_menu_send"
android:layout_alignParentRight="true"
android:scaleType="fitCenter"/>
<ImageButton
android:id="@+id/BT_editTask"
android:layout_width="@dimen/new_task_bat_btn_width"
android:layout_height="match_parent"
android:padding="@dimen/new_task_bat_btn_padding"
android:background="@drawable/selectable_background_cardbank"
android:src="@drawable/ic_menu_edit"
android:layout_toLeftOf="@id/BT_task_new"
android:scaleType="fitCenter"/>
<EditText
android:id="@+id/ET_addTask"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:hint="@string/create_habit_hint"
android:imeOptions="actionDone"
android:inputType="textCapSentences|textNoSuggestions"
android:layout_toLeftOf="@id/BT_editTask">
<!-- android:textColor="@color/white"
android:textColorHint="#FFC0C0C0"
-->
</EditText>
</RelativeLayout>
</LinearLayout>
<android.support.v4.view.ViewPager
android:id="@+id/home_pannels_pager"
android:layout_width="0dip"
android:layout_weight="0.5"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:paddingLeft="8dip"
android:layout_marginBottom="@dimen/activity_vertical_margin"
android:layout_marginRight="@dimen/activity_horizontal_margin"
>
</android.support.v4.view.ViewPager>
</LinearLayout>

View file

@ -1,76 +0,0 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="0dip"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<include layout="@layout/avatar_with_bars"
android:id="@+id/avatar_with_bars"
android:layout_width="match_parent"
android:paddingRight="@dimen/activity_horizontal_margin"
android:layout_height="wrap_content"/>
<android.support.v4.view.ViewPager
android:id="@+id/home_pannels_pager"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="0.9"
android:background="@android:color/transparent" />
<ProgressBar
android:id="@+id/PB_AsyncTask"
style="@style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/PB_marginBottom"
android:indeterminate="true" />
<RelativeLayout
android:id="@+id/RL_addTask"
android:layout_width="match_parent"
android:layout_height="@dimen/new_task_bar_size"
android:layout_gravity="end"
android:background="@drawable/bottom_bar_bg"
android:gravity="bottom"
android:orientation="horizontal"
android:paddingBottom="0dp">
<ImageButton
android:id="@+id/BT_task_new"
android:layout_width="@dimen/new_task_bat_btn_width"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_gravity="top"
android:background="@drawable/selectable_background_cardbank"
android:padding="@dimen/new_task_bat_btn_padding"
android:scaleType="fitCenter"
android:src="@drawable/ic_menu_send" />
<ImageButton
android:id="@+id/BT_editTask"
android:layout_width="@dimen/new_task_bat_btn_width"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/BT_task_new"
android:background="@drawable/selectable_background_cardbank"
android:padding="@dimen/new_task_bat_btn_padding"
android:scaleType="fitCenter"
android:src="@drawable/ic_menu_edit" />
<EditText
android:id="@+id/ET_addTask"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toLeftOf="@id/BT_editTask"
android:hint="@string/create_habit_hint"
android:imeOptions="actionDone"
android:inputType="textCapSentences|textNoSuggestions">
<!-- android:textColor="@color/white"
android:textColorHint="#FFC0C0C0"
-->
</EditText>
</RelativeLayout>
</LinearLayout>

View file

@ -13,7 +13,7 @@
android:layout_height="match_parent"
app:viewpager_logoMarginTop="70dp"
app:viewpager_pagerTitleStrip="@layout/material_view_pager_pagertitlestrip_standard"
app:viewpager_color="@color/colorPrimary"
app:viewpager_color="@color/brand"
app:viewpager_headerHeight="220dp"
app:viewpager_headerAlpha="1"
app:viewpager_logo="@layout/avatar_with_bars"

View file

@ -1,7 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".FABActivity">
<RelativeLayout
android:id="@+id/relativeLayoutView"
android:layout_width="match_parent"
android:layout_height="match_parent">
@ -12,14 +20,18 @@
android:scrollbarSize="3dp"
android:scrollbarThumbVertical="@color/md_grey_500"
android:scrollbars="vertical"/>
</RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="@id/recyclerView"
android:layout_marginBottom="32dp"
android:layout_marginRight="20dp"/>
android:layout_marginBottom="16dp"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
app:fabSize="normal"
app:layout_anchor="@id/coordinatorLayout"
app:layout_anchorGravity="bottom|right|end"
app:backgroundTint="@color/brand"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

View file

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<include layout="@layout/activity_main"/>
<!-- The navigation drawer -->
<include layout="@layout/drawer"
android:layout_gravity="start"/>
</android.support.v4.widget.DrawerLayout>

View file

@ -1,7 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.habitrpg.android.habitica.MainActivityNew">
tools:context="com.habitrpg.android.habitica.MainActivity">
<!-- Search, should appear as action button -->
<item android:id="@+id/action_search"

View file

@ -8,7 +8,7 @@
<!-- API 11 theme customizations can go here. -->
</style>
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:listSeparatorTextViewStyle">@style/MyOwnListSeperatorTextViewStyle
</item>
<!-- All customizations that are NOT specific to a particular API-level can go here. -->

View file

@ -5,7 +5,7 @@
AppBaseTheme from BOTH res/values/styles.xml and
res/values-v11/styles.xml on API 14+ devices.
-->
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.DarkActionBar">
<style name="AppBaseTheme" parent="android:Theme.Holo.Light.NoActionBar">
<!-- API 14 theme customizations can go here. -->
</style>

View file

@ -9,6 +9,7 @@
<color name="mpColor">#4781e7</color>
<color name="mpColorBackground">#eff4fd</color>
<color name="mpColorForeground">#051228</color>
<color name="brand">#7a12f8</color>
<!-- HabitRPG task color -->
<color name="worst">#E6B8AF</color>

View file

@ -3,7 +3,7 @@
<!-- Application theme. -->
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="@style/Theme.AppCompat.Light.NoActionBar">
<item name="android:listSeparatorTextViewStyle">@style/MyOwnListSeperatorTextViewStyle</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
@ -66,8 +66,6 @@
<item name="android:textAllCaps"
tools:targetApi="14">true</item>
<item name="android:textSize">14sp</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
@ -77,8 +75,8 @@
<style name="CustomTheme" parent="style/MaterialDrawerTheme.TranslucentStatus">
<!-- ...and here we setting appcompats color theming attrs -->
<item name="colorPrimary">@color/material_drawer_primary</item>
<item name="colorPrimaryDark">@color/material_drawer_primary_dark</item>
<item name="colorPrimary">@color/brand</item>
<item name="colorPrimaryDark">@color/brand</item>
<item name="colorAccent">@color/md_amber_200</item>
<!-- MaterialDrawer specific values -->

View file

@ -9,7 +9,6 @@ import android.app.DatePickerDialog.OnDateSetListener;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.util.Log;
@ -37,8 +36,6 @@ import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo;
import com.magicmicky.habitrpgwrapper.lib.utils.DaysUtils;
import org.json.JSONObject;
import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.*;
import static com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType.habit;
@ -145,20 +142,20 @@ public class AddTaskDialog extends DialogFragment implements OnDateSetListener,
if (mEditMode) {
// this.reconstructObjectFrom(json);
switch (hType) {
/*switch (hType) {
case todo:
this.populate(((MainActivity) getActivity()).getTodo(pos));
this.populate(((MainActivityOld) getActivity()).getTodo(pos));
break;
case daily:
this.populate(((MainActivity) getActivity()).getDaily(pos));
this.populate(((MainActivityOld) getActivity()).getDaily(pos));
break;
case reward:
this.populate(((MainActivity) getActivity()).getReward(pos));
this.populate(((MainActivityOld) getActivity()).getReward(pos));
break;
case habit:
this.populate(((MainActivity) getActivity()).getHabit(pos));
this.populate(((MainActivityOld) getActivity()).getHabit(pos));
break;
}
}*/
}
builder.setTitle(getString(R.string.new_task, hType.toString()))
.setPositiveButton(R.string.dialog_confirm_button, new DialogInterface.OnClickListener() {

File diff suppressed because it is too large Load diff

View file

@ -1,474 +0,0 @@
package com.habitrpg.android.habitica;
import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Toast;
import com.github.florent37.materialviewpager.MaterialViewPager;
import com.habitrpg.android.habitica.callbacks.HabitRPGUserCallback;
import com.habitrpg.android.habitica.databinding.SidebarHeaderBinding;
import com.habitrpg.android.habitica.prefs.PrefsActivity;
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel;
import com.habitrpg.android.habitica.ui.EditTextDrawer;
import com.habitrpg.android.habitica.ui.adapter.HabitItemRecyclerViewAdapter;
import com.habitrpg.android.habitica.ui.fragments.RecyclerViewFragment;
import com.instabug.wrapper.support.activity.InstabugAppCompatActivity;
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
import com.magicmicky.habitrpgwrapper.lib.models.Tag;
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem;
import com.mikepenz.materialdrawer.Drawer;
import com.mikepenz.materialdrawer.DrawerBuilder;
import com.mikepenz.materialdrawer.model.DividerDrawerItem;
import com.mikepenz.materialdrawer.model.PrimaryDrawerItem;
import com.mikepenz.materialdrawer.model.SecondaryDrawerItem;
import com.mikepenz.materialdrawer.model.SectionDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import butterknife.ButterKnife;
import butterknife.InjectView;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
public class MainActivityNew extends InstabugAppCompatActivity
implements HabitRPGUserCallback.OnUserReceived, Callback<Void> {
static final int ABOUT = 12;
//region View Elements
@InjectView(R.id.materialViewPager)
MaterialViewPager materialViewPager;
Toolbar toolbar;
Drawer drawer;
Drawer filterDrawer;
//endregion
Map<Integer, RecyclerViewFragment> ViewFragmentsDictionary = new HashMap<Integer, RecyclerViewFragment>();
List<HabitItem> TaskList = new ArrayList<HabitItem>();
private HostConfig hostConfig;
APIHelper mAPIHelper;
android.support.v4.view.ViewPager viewPager;
// just to test the view
public HabitRPGUser User = null;
AvatarWithBarsViewModel avatarInSidebar;
AvatarWithBarsViewModel avatarInHeader;
SidebarHeaderBinding sidebarHeaderBinding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_new);
// Inject Controls
ButterKnife.inject(this);
this.hostConfig = PrefsActivity.fromContext(this);
toolbar = materialViewPager.getToolbar();
setSupportActionBar(toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setHomeButtonEnabled(false);
}
toolbar.setPadding(0, getResources().getDimensionPixelSize(R.dimen.tool_bar_top_padding), 0, 0);
}
materialViewPager.setBackgroundColor(getResources().getColor(R.color.white));
View sidebarHeaderView = LayoutInflater.from(this).inflate(R.layout.sidebar_header, null, false);
sidebarHeaderBinding = DataBindingUtil.bind(sidebarHeaderView);
avatarInSidebar = new AvatarWithBarsViewModel(this, sidebarHeaderView.findViewById(R.id.avatar_with_bars));
View mPagerRootView = materialViewPager.getRootView();
View avatarHeaderView = mPagerRootView.findViewById(R.id.avatar_with_bars_layout);
avatarInHeader = new AvatarWithBarsViewModel(this, avatarHeaderView);
drawer = new DrawerBuilder()
.withActivity(this)
.withToolbar(toolbar)
.withHeaderDivider(false)
.withTranslucentStatusBar(true)
.withAnimateDrawerItems(true)
.addDrawerItems(
new PrimaryDrawerItem().withName("Tasks"),
new SectionDrawerItem().withName("Social"),
new PrimaryDrawerItem().withName("Tavern"),
new PrimaryDrawerItem().withName("Party"),
new PrimaryDrawerItem().withName("Guilds"),
new PrimaryDrawerItem().withName("Challenges"),
new SectionDrawerItem().withName("Inventory"),
new PrimaryDrawerItem().withName("Avatar"),
new PrimaryDrawerItem().withName("Equipment"),
new PrimaryDrawerItem().withName("Stable"),
new DividerDrawerItem(),
new SecondaryDrawerItem().withName("News"),
new SecondaryDrawerItem().withName("Settings"),
new SecondaryDrawerItem().withName("About").withIdentifier(ABOUT)
)
.withHeader(sidebarHeaderView)
.withStickyFooterDivider(false)
.withStickyFooter(R.layout.sidebar_sticky_footer)
.withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
@Override
public boolean onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) {
// do something with the clicked item :D
switch (drawerItem.getIdentifier()) {
case ABOUT:
startActivity(new Intent(MainActivityNew.this, AboutActivity.class));
return false;
}
return true;
}
})
.build();
final android.content.Context context = getApplicationContext();
filterDrawer = new DrawerBuilder()
.withActivity(this)
.withOnDrawerItemLongClickListener(new Drawer.OnDrawerItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l, IDrawerItem iDrawerItem) {
Toast toast = Toast.makeText(context, "Long Pressed", Toast.LENGTH_LONG);
toast.show();
return true;
}
})
.withDrawerGravity(Gravity.RIGHT)
.append(drawer);
viewPager = materialViewPager.getViewPager();
viewPager.setOffscreenPageLimit(6);
viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {}
@Override
public void onPageSelected(int position) {
Log.d("PageSelected", "P=" + position);
RecyclerViewFragment fragment = ViewFragmentsDictionary.get(position);
if (fragment == null || fragment.mRecyclerView == null)
return;
// fragment.mRecyclerView.smoothScrollToPosition(r.nextInt(fragment.mRecyclerView.getAdapter().getItemCount()));
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
materialViewPager.getViewPager().setCurrentItem(1);
}
@Override
protected void onResume() {
super.onResume();
this.mAPIHelper = new APIHelper(this, hostConfig);
mAPIHelper.retrieveUser(new HabitRPGUserCallback(this));
}
public void FillTasks()
{
android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
viewPager.setAdapter(new FragmentPagerAdapter(fragmentManager) {
int oldPosition = -1;
@Override
public Fragment getItem(int position) {
int layoutOfType;
RecyclerViewFragment fragment;
String fragmentkey = "Recycler$" + position;
switch (position) {
case 0:
layoutOfType = R.layout.habit_item_card;
fragment = RecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter(User.getHabits(), layoutOfType, HabitItemRecyclerViewAdapter.HabitViewHolder.class), fragmentkey);
break;
case 1:
layoutOfType = R.layout.daily_item_card;
fragment = RecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter(User.getDailys(), layoutOfType, HabitItemRecyclerViewAdapter.DailyViewHolder.class), fragmentkey);
break;
case 3:
layoutOfType = R.layout.reward_item_card;
fragment = RecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter(User.getRewards(), layoutOfType, HabitItemRecyclerViewAdapter.RewardViewHolder.class), fragmentkey);
break;
default:
layoutOfType = R.layout.todo_item_card;
fragment = RecyclerViewFragment.newInstance(new HabitItemRecyclerViewAdapter(User.getTodos(), layoutOfType, HabitItemRecyclerViewAdapter.TodoViewHolder.class), fragmentkey);
}
// ViewFragmentsDictionary.put(position, fragment);
return fragment;
}
@Override
public void setPrimaryItem(ViewGroup container, int position, Object object) {
super.setPrimaryItem(container, position, object);
//only if position changed
if (position == oldPosition)
return;
oldPosition = position;
int color = 0;
String imageUrl = "";
switch (position % 4) {
case 0:
imageUrl = "http://cdn1.tnwcdn.com/wp-content/blogs.dir/1/files/2014/06/wallpaper_51.jpg";
color = getResources().getColor(R.color.blue);
break;
case 1:
imageUrl = "https://fs01.androidpit.info/a/63/0e/android-l-wallpapers-630ea6-h900.jpg";
color = getResources().getColor(R.color.green);
break;
case 2:
imageUrl = "http://www.droid-life.com/wp-content/uploads/2014/10/lollipop-wallpapers10.jpg";
color = getResources().getColor(R.color.cyan);
break;
case 3:
imageUrl = "http://www.tothemobile.com/wp-content/uploads/2014/07/original.jpg";
color = getResources().getColor(R.color.red);
break;
}
final int fadeDuration = 400;
//materialViewPager.setImageUrl(imageUrl, fadeDuration);
materialViewPager.setColor(color, fadeDuration);
}
@Override
public int getCount() {
return 4;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "Habits";
case 1:
return "Dailies";
case 2:
return "Todos";
case 3:
return "Rewards";
/* case 4:
return "Skills";
case 5:
return "Skills 2";*/
}
return "";
}
});
materialViewPager.getPagerTitleStrip().setViewPager(viewPager);
}
public void FillTagFilterDrawer() {
filterDrawer.removeAllItems();
filterDrawer.addItems(
new SectionDrawerItem().withName("Filter by Tag"),
new EditTextDrawer()
);
for (Tag t : User.getTags()) {
filterDrawer.addItem(
new PrimaryDrawerItem().withName(t.getName()).withBadge("" + CountTagUsedInTasks(t.getId()))
);
}
}
/**
* Anyone a better solution to count the Tag?
*/
public int CountTagUsedInTasks(String tagId) {
int count = 0;
for (HabitItem task : TaskList) {
if (task.getTags().contains(tagId))
count++;
}
return count;
}
public int adjustAlpha(int color, float factor) {
int alpha = Math.round(Color.alpha(color) * factor);
int red = Color.red(color);
int green = Color.green(color);
int blue = Color.blue(color);
return Color.argb(alpha, red, green, blue);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main_activity_new, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id) {
case R.id.action_search:
filterDrawer.openDrawer();
return true;
case R.id.action_toggle_sleep:
mAPIHelper.toggleSleep(this);
User.getPreferences().setSleep(!User.getPreferences().isSleep());
updateUserAvatars();
return true;
}
return super.onOptionsItemSelected(item);
}
private void updateUserAvatars()
{
avatarInSidebar.UpdateData(User);
avatarInHeader.UpdateData(User);
}
@Override
public void onUserReceived(HabitRPGUser user) {
TaskList.clear();
User = user;
if(user == null)
return;
toolbar.setTitle(User.getProfile().getName() + " - Lv" + User.getStats().getLvl());
TaskList.addAll(User.getHabits());
TaskList.addAll(User.getDailys());
TaskList.addAll(User.getTodos());
TaskList.addAll(User.getRewards());
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
FillTasks();
updateUserAvatars();
android.support.v7.app.ActionBarDrawerToggle actionBarDrawerToggle = drawer.getActionBarDrawerToggle();
if (actionBarDrawerToggle != null) {
actionBarDrawerToggle.setDrawerIndicatorEnabled(true);
}
sidebarHeaderBinding.setUserName(User.getProfile().getName() + " - Lv" + User.getStats().getLvl());
Double goldPoints = User.getStats().getGp();
sidebarHeaderBinding.setGold("" + goldPoints.intValue());
sidebarHeaderBinding.setSilver("" + (int) ((goldPoints - goldPoints.intValue()) * 100));
FillTagFilterDrawer();
}
}, 100);
}
@Override
public void onUserFail() {
}
@Override
public void success(Void aVoid, Response response) {
}
@Override
public void failure(RetrofitError error) {
}
}

View file

@ -266,7 +266,7 @@ public abstract class CardFragment extends Fragment implements OnTasksChanged {
if(v.getParent()!=null) {
String direction = upOrDown(v, getItem(((View) v.getParent()).getId()));
String id = getIdString(((View) v.getParent()).getId());
((MainActivity) getActivity()).onPreResult();
/*((MainActivityOld) getActivity()).onPreResult();*/
Log.d("OMG", "id : " + id + " - " + direction);
mAPIHelper.updateTaskDirection(id,direction, new TaskScoringCallback((MainActivity) getActivity()));
} else {
@ -391,7 +391,7 @@ public abstract class CardFragment extends Fragment implements OnTasksChanged {
return true;
case R.id.deleteConfirmMenuBT:
HabitItem taskToDel = mAdapter.getItem(mAdapter.getItemCheckedPos());
((MainActivity) getActivity()).onPreResult();
//((MainActivity) getActivity()).onPreResult();
mAPIHelper.deleteTask(taskToDel, new TaskDeletionCallback((MainActivity) getActivity(), taskToDel));
mActionMode.finish();
return true;