mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Remove old code
This commit is contained in:
parent
50ba0e07ab
commit
a7e78dbd68
14 changed files with 0 additions and 1501 deletions
|
|
@ -1,96 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="@dimen/card_horizontal_padding"
|
||||
android:paddingTop="@dimen/card_horizontal_padding"
|
||||
android:paddingRight="@dimen/card_vertical_padding"
|
||||
android:paddingLeft="@dimen/card_vertical_padding"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/card_background_shadow"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@android:color/white"
|
||||
android:gravity="center_vertical"
|
||||
android:padding="4dp" >
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical|right"
|
||||
android:orientation="horizontal"
|
||||
android:paddingLeft="8dp"
|
||||
android:paddingRight="8dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
style="@style/CardTitle"
|
||||
android:layout_weight="0.8"
|
||||
android:layout_width="0dip"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="title" />
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gold"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_weight="0.1"
|
||||
android:visibility="gone"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right|center_vertical"
|
||||
android:gravity="right|center_vertical"
|
||||
android:text="GP" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/IMG_gold"
|
||||
android:visibility="gone"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/gold"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/silver"
|
||||
android:layout_weight="0.1"
|
||||
android:visibility="gone"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right|center_vertical"
|
||||
android:gravity="right|center_vertical"
|
||||
android:text="SP" />
|
||||
<ImageView
|
||||
android:id="@+id/IMG_silver"
|
||||
android:visibility="gone"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/silver"/>
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:background="@color/stroke" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/task_list_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1"
|
||||
android:clickable="true"
|
||||
tools:listitem="@layout/habit"
|
||||
android:choiceMode="singleChoice"
|
||||
>
|
||||
</ListView>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
|
@ -1,7 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/TV_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
style="@style/CardLightText" />
|
||||
|
|
@ -1,74 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.habitrpg.android.habitica.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/row_size"
|
||||
android:background="@drawable/drawer_activated_background"
|
||||
android:clickable="false"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingBottom="0dp"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingTop="0dp"
|
||||
style="@style/CardText"
|
||||
>
|
||||
|
||||
<Button
|
||||
android:id="@+id/minus"
|
||||
android:layout_width="@dimen/minus_plus_buttonsize"
|
||||
android:layout_height="@dimen/minus_plus_buttonsize"
|
||||
android:text="@string/minus_sign"
|
||||
android:background="@drawable/selectable_background_cardbank"
|
||||
android:gravity="center"
|
||||
android:textSize="30sp"
|
||||
android:layout_marginTop="@dimen/view_layout_margin"
|
||||
android:layout_marginBottom="@dimen/view_layout_margin"
|
||||
|
||||
/>
|
||||
<View
|
||||
android:id="@+id/btnDivider"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="1dp"
|
||||
android:layout_marginTop="@dimen/view_layout_margin"
|
||||
android:layout_marginBottom="@dimen/view_layout_margin"
|
||||
android:background="@color/stroke" />
|
||||
<Button
|
||||
android:id="@+id/plus"
|
||||
android:layout_width="@dimen/minus_plus_buttonsize"
|
||||
android:layout_height="@dimen/minus_plus_buttonsize"
|
||||
android:text="@string/plus_sign"
|
||||
android:background="@drawable/selectable_background_cardbank"
|
||||
android:gravity="center"
|
||||
android:textSize="30sp"
|
||||
android:layout_marginTop="@dimen/view_layout_margin"
|
||||
android:layout_marginBottom="@dimen/view_layout_margin"/>
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
>
|
||||
|
||||
<!-- <View -->
|
||||
<!-- android:id="@+id/V_color_indic" -->
|
||||
<!-- android:layout_width="50dp" -->
|
||||
<!-- android:layout_height="10dp" -->
|
||||
<!-- android:layout_marginRight="30dp" -->
|
||||
<!-- android:background="@color/bad" -->
|
||||
<!-- android:layout_gravity="top|right" /> -->
|
||||
<ImageView
|
||||
android:id="@+id/IV_task_color"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_gravity="right"
|
||||
android:src="@drawable/triangle_neutral"/>
|
||||
<CheckedTextView
|
||||
android:id="@+id/TV_title"
|
||||
style="@style/CardText"
|
||||
android:layout_gravity="center|left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:gravity="left"/>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
</com.habitrpg.android.habitica.CheckableLinearLayout>
|
||||
|
|
@ -1,34 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.habitrpg.android.habitica.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/row_size"
|
||||
android:background="@drawable/item_background"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingBottom="0dp"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingTop="0dp"
|
||||
style="@style/CardText"
|
||||
>
|
||||
|
||||
<Button
|
||||
android:id="@+id/plus"
|
||||
android:layout_width="70dp"
|
||||
android:layout_height="@dimen/btn_height_reward"
|
||||
android:background="@drawable/selectable_background_cardbank"
|
||||
android:gravity="center|left"
|
||||
android:paddingLeft="5dp"
|
||||
android:textSize="20sp" />
|
||||
|
||||
|
||||
<CheckedTextView
|
||||
android:id="@+id/TV_title"
|
||||
style="@style/CardText"
|
||||
android:layout_gravity="center|left"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:gravity="left"/>
|
||||
|
||||
|
||||
</com.habitrpg.android.habitica.CheckableLinearLayout>
|
||||
|
|
@ -1,99 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout>
|
||||
|
||||
<data>
|
||||
<variable
|
||||
name="userName"
|
||||
type="String"/>
|
||||
|
||||
|
||||
<variable
|
||||
name="gold"
|
||||
type="String"/>
|
||||
<variable
|
||||
name="silver"
|
||||
type="String"/>
|
||||
|
||||
</data>
|
||||
|
||||
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:orientation="horizontal"
|
||||
android:paddingRight="@dimen/activity_horizontal_margin"
|
||||
android:paddingTop="@dimen/tool_bar_top_padding"
|
||||
android:background="@color/md_grey_700"
|
||||
android:paddingLeft="@dimen/activity_horizontal_margin">
|
||||
|
||||
<include layout="@layout/avatar_with_bars" android:id="@+id/avatar_with_bars"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/userNameText"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true"
|
||||
/>
|
||||
|
||||
<TableLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:id="@+id/tableLayout"
|
||||
android:layout_below="@+id/avatar_with_bars"
|
||||
android:layout_marginLeft="@dimen/avatar_width">
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/imageView"
|
||||
android:layout_column="0"
|
||||
android:src="@drawable/gold" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/imageView2"
|
||||
android:layout_column="1"
|
||||
android:src="@drawable/silver" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@{gold}"
|
||||
android:id="@+id/goldText"
|
||||
android:layout_column="0"
|
||||
android:gravity="center" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@{silver}"
|
||||
android:id="@+id/silverText"
|
||||
android:layout_column="1"
|
||||
android:gravity="center" />
|
||||
</TableRow>
|
||||
</TableLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:text="@{userName}"
|
||||
android:id="@+id/userNameText"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
|
||||
</RelativeLayout>
|
||||
</layout>
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent" android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:background="@color/md_grey_800"
|
||||
android:padding="5dp">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:text="Version: X.X.X.X"
|
||||
android:id="@+id/textView" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="This is a sticky footer"
|
||||
android:id="@+id/textView2" />
|
||||
</LinearLayout>
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<com.habitrpg.android.habitica.CheckableLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/CardText"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/row_size"
|
||||
android:background="@drawable/item_background"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingBottom="0dp"
|
||||
android:paddingLeft="4dp"
|
||||
android:paddingRight="0dp"
|
||||
android:paddingTop="0dp">
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/plus"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_marginBottom="14dp"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:layout_marginTop="14dp"
|
||||
android:gravity="center" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/IV_task_color"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
android:layout_gravity="right"
|
||||
android:src="@drawable/triangle_worst" />
|
||||
|
||||
<CheckedTextView
|
||||
android:id="@+id/TV_title"
|
||||
style="@style/CardText"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center|left"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:gravity="left" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/BT_checklist"
|
||||
android:layout_width="55dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="right"
|
||||
android:background="@color/transparent"
|
||||
android:layout_marginRight="30dp"
|
||||
android:visibility="gone"
|
||||
android:src="@drawable/ic_action_list" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</com.habitrpg.android.habitica.CheckableLinearLayout>
|
||||
|
|
@ -1,29 +0,0 @@
|
|||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_showTestActivity"
|
||||
android:orderInCategory="101"
|
||||
app:showAsAction="never"
|
||||
android:title="Test Activity"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_showChangelogActivity"
|
||||
android:orderInCategory="102"
|
||||
app:showAsAction="never"
|
||||
android:title="About"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/action_settings"/>
|
||||
<item android:id="@+id/action_logout"
|
||||
android:orderInCategory="98"
|
||||
android:title="@string/logout"/>
|
||||
<item android:id="@+id/action_refresh"
|
||||
android:orderInCategory="99"
|
||||
app:showAsAction="never"
|
||||
android:title="@string/action_refresh"/>
|
||||
|
||||
</menu>
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.adapter;
|
||||
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.habitrpg.android.habitica.ui.fragments.CardFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.DailyFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.HabitFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.RewardFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.ToDoFragment;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class HabitItemAdapter extends FragmentPagerAdapter {
|
||||
private SparseArray<CardFragment> fragments = new SparseArray<CardFragment>();
|
||||
List<HabitItem> items;
|
||||
|
||||
private static final String TAG = "MainActivity";
|
||||
|
||||
public HabitItemAdapter(FragmentManager fm) {
|
||||
super(fm);
|
||||
Log.v(TAG + "_FP", "Reinstanciating items");
|
||||
CardFragment h = new HabitFragment();
|
||||
CardFragment d = new DailyFragment();
|
||||
CardFragment t = new ToDoFragment();
|
||||
CardFragment r = new RewardFragment();
|
||||
fragments.put(0, h);
|
||||
fragments.put(1, d);
|
||||
fragments.put(2, t);
|
||||
fragments.put(3, r);
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CardFragment getItem(int position) {
|
||||
Log.v(TAG + "_FP", "instantiating fragment " + position);
|
||||
return fragments.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
CardFragment fragment = (CardFragment) super.instantiateItem(container, position);
|
||||
Log.v(TAG + "_FP", "adding fragment" + position);
|
||||
fragments.put(position, fragment);
|
||||
if (items != null) {
|
||||
fragment.onChange(items);
|
||||
//fragment.onTagFilter(selectedTags);
|
||||
}
|
||||
return fragment;
|
||||
}
|
||||
/*@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
Log.v(TAG + "_FragmentPager", "removing fragment" + position);
|
||||
fragments.remove(position);
|
||||
super.destroyItem(container, position, object);
|
||||
}*/
|
||||
|
||||
|
||||
public void notifyFragments(List<HabitItem> items) {
|
||||
this.items = items;
|
||||
for (int i = 0; i <= 3; i++) { // f : fragments) {
|
||||
CardFragment f = fragments.get(i);
|
||||
if (f != null) {
|
||||
f.onChange(items);
|
||||
//f.onTagFilter(selectedTags);
|
||||
} else {
|
||||
Log.w(TAG + "_Notify", "no fragment " + i);
|
||||
}
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void filterFragments(List<String> tags) {
|
||||
for (int i = 0; i <= 3; i++) { // f : fragments) {
|
||||
CardFragment f = fragments.get(i);
|
||||
if (f != null)
|
||||
f.onTagFilter(tags);
|
||||
else
|
||||
Log.w(TAG + "_Filters", "no fragment " + i);
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -1,416 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import com.habitrpg.android.habitica.APIHelper;
|
||||
import com.habitrpg.android.habitica.AddTaskDialog;
|
||||
import com.habitrpg.android.habitica.HostConfig;
|
||||
import com.habitrpg.android.habitica.MainActivity;
|
||||
import com.habitrpg.android.habitica.OnTasksChanged;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.callbacks.TaskDeletionCallback;
|
||||
import com.habitrpg.android.habitica.callbacks.TaskScoringCallback;
|
||||
import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward;
|
||||
|
||||
import de.keyboardsurfer.android.widget.crouton.Crouton;
|
||||
import de.keyboardsurfer.android.widget.crouton.Style;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.app.ActionBarActivity;
|
||||
import android.support.v7.view.ActionMode;
|
||||
import android.util.Log;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public abstract class CardFragment extends Fragment implements OnTasksChanged {
|
||||
private static final String TAG = "CardFragment";
|
||||
/**
|
||||
* If we receive a notification of tasks (by the @{code OnTasksChanged} implementation) <br/>
|
||||
* Before the fragment is shown, we need to save the tasks.
|
||||
*/
|
||||
private List<HabitItem> tmpTasks= new ArrayList<HabitItem>();
|
||||
protected MyAdapter mAdapter;
|
||||
private ListView mListView;
|
||||
protected APIHelper mAPIHelper;
|
||||
private List<String> tmpTags = new ArrayList<String>();
|
||||
private ActionMode mActionMode;
|
||||
private static final String API_KEY ="b89ef880-7e07-4d13-8a5f-b6be25437fd8";
|
||||
private static final String USER_KEY ="710f41f1-4113-4d8a-9714-79a84edd6175";
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
Log.d(TAG, "oncreate call");
|
||||
//setRetainInstance(true);
|
||||
View view = inflater.inflate(R.layout.card_ex, container,false);
|
||||
mListView = (ListView) view.findViewById(R.id.task_list_view);
|
||||
|
||||
|
||||
((TextView) view.findViewById(R.id.title)).setText(this.getTitle());
|
||||
if( mListView.getAdapter() == null || this.mAdapter ==null) {
|
||||
this.mAdapter = this.instantiateAdapter(this.getActivity());
|
||||
Log.d(TAG + this.getTitle(),"Adapter was null... Not anymore");
|
||||
mListView.setAdapter(mAdapter);
|
||||
}
|
||||
this.mAdapter = (MyAdapter) mListView.getAdapter();
|
||||
|
||||
if(tmpTasks.size() != 0) {
|
||||
Log.v(TAG + "tmpdata" + this.getTitle(), "Temp data (" + tmpTasks.size() + " tasks) already created. Sending them to the adapter...");
|
||||
this.mAdapter.updateTasks(tmpTasks);
|
||||
this.mAdapter.notifyDataSetChanged();
|
||||
tmpTasks.clear();
|
||||
|
||||
} else {
|
||||
Log.v(TAG + "tmpdata" + this.getTitle(), "No temp data...");
|
||||
}
|
||||
|
||||
if(tmpTags.size()!=0) {
|
||||
Log.v(TAG+"tmpdata_tags"+ this.getTitle(),"Temp ("+tmpTags.size() +" tags) already created. Sending them to the adapter...");
|
||||
this.mAdapter.filterTasks(tmpTags);
|
||||
this.mAdapter.notifyDataSetChanged();
|
||||
tmpTags.clear();
|
||||
} else {
|
||||
Log.v(TAG + "tmpdata_tags" + this.getTitle(), "No temp tags...");
|
||||
}
|
||||
mListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
||||
@Override
|
||||
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
if (mActionMode != null) {
|
||||
toggleTaskSelection(i);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Start the CAB using the ActionMode.Callback defined above
|
||||
mActionMode = ((ActionBarActivity) getActivity()).startSupportActionMode(mActionModeCallback);
|
||||
toggleTaskSelection(i);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return view;
|
||||
}
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
|
||||
if (isVisibleToUser) {
|
||||
|
||||
}
|
||||
else {
|
||||
if(this.mActionMode!=null) {
|
||||
this.mActionMode.finish();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void toggleTaskSelection(int pos) {
|
||||
boolean new_status = !mAdapter.isItemChecked(pos);
|
||||
mListView.setItemChecked(pos, new_status);
|
||||
mAdapter.setItemChecked(pos, new_status);
|
||||
int nbItemChecked = mAdapter.getNbItemChecked();
|
||||
if (mActionMode != null) {
|
||||
if (nbItemChecked != 0) {
|
||||
mActionMode.setTitle(getString(R.string.cab_selected, nbItemChecked));
|
||||
} else {
|
||||
mActionMode.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
HostConfig cfg = PrefsActivity.fromContext(this.getActivity());
|
||||
this.mAPIHelper = new APIHelper(getActivity(), cfg);
|
||||
|
||||
}
|
||||
protected abstract HabitType getTaskType();
|
||||
/**
|
||||
* Filter the data depending of the type of the inherited class
|
||||
* @param items the items to filter
|
||||
* @return the list of {@link HabitItem} filtered
|
||||
*/
|
||||
protected abstract List<HabitItem> filterData(List<HabitItem> items);
|
||||
|
||||
protected abstract String getTitle();
|
||||
public abstract MyAdapter instantiateAdapter(Context c);
|
||||
/**
|
||||
* @return the callback
|
||||
*/
|
||||
/*public OnTasksChanged getCallback() {
|
||||
return this;
|
||||
}*/
|
||||
@Override
|
||||
public void onTagFilter(List<String> tags) {
|
||||
Log.d(TAG + "tmpdata_tagfilter"+ this.getTitle(), "Filtering tasks with " + tags.size() + " tag(s)");
|
||||
if(this.mAdapter ==null) {
|
||||
/* Context ac = this.getActivity();
|
||||
if(ac != null) {
|
||||
Log.d(TAG +"tmpdata_tagfilter"+ this.getTitle(),"Adapter not set up: setting it up + filtering tasks");
|
||||
this.mAdapter = instantiateAdapter(ac);
|
||||
this.mAdapter.filterTasks(tags);
|
||||
this.mAdapter.notifyDataSetChanged();
|
||||
|
||||
} else {
|
||||
Log.d(TAG +"tmpdata_tagfilter"+ this.getTitle(), "Unable to create the adapter. Temping tags data");
|
||||
}*/
|
||||
Log.d(TAG +"tmpdata_tagfilter"+ this.getTitle(), "Unable to create the adapter. Temping tags data");
|
||||
|
||||
this.tmpTags.clear();
|
||||
this.tmpTags.addAll(tags);
|
||||
|
||||
} else {
|
||||
Log.d(TAG +"tmpdata_tagfilter"+ this.getTitle(),"Adapter set up: filtering tasks");
|
||||
this.mAdapter.filterTasks(tags);
|
||||
this.mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChange(List<HabitItem> items) {
|
||||
Log.d(TAG +"_task","Changing data (" + items.size() + " items)");
|
||||
if(this.mAdapter ==null) {
|
||||
this.tmpTasks.clear();
|
||||
this.tmpTasks.addAll(filterData(items));
|
||||
Log.d(TAG + "tmpdata" + this.getTitle() +"_callbackTaskChanged","The adapter isn't set up yet. Saving "+ tmpTasks.size() + " tasks in the temp");
|
||||
/*Context ac = this.getActivity();
|
||||
if(ac != null) {
|
||||
Log.d(TAG + "tmpdata" + this.getTitle() +"_callbackTaskChanged","Adapter created: sending temp data, deleting temp.");
|
||||
this.mAdapter = instantiateAdapter(ac);
|
||||
this.mAdapter.updateTasks(this.tmpTasks);
|
||||
this.mAdapter.notifyDataSetChanged();
|
||||
this.tmpTasks.clear();
|
||||
} else {
|
||||
Log.d(TAG + "tmpdata" + this.getTitle() +"_callbackTaskChanged", "Unable to create the adapter. What about temp data?");
|
||||
}*/
|
||||
|
||||
} else {
|
||||
this.mAdapter.updateTasks(filterData(items));
|
||||
this.mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The Adapter class that deals with the different data
|
||||
* @author MagicMicky
|
||||
*
|
||||
*/
|
||||
protected abstract class MyAdapter extends BaseAdapter {
|
||||
private List<HabitItem> tasks;
|
||||
private List<HabitItem> filteredTasks;
|
||||
protected Context c;
|
||||
private boolean isFiltered;
|
||||
private List<String> tags;
|
||||
private int checkedItem=-1;
|
||||
|
||||
public MyAdapter(Context c, List<HabitItem> tasks) {
|
||||
Log.d("ADAPTER", "adapter called");
|
||||
this.tasks = tasks;
|
||||
this.c=c;
|
||||
this.isFiltered=false;
|
||||
this.filteredTasks = new ArrayList<HabitItem>();
|
||||
this.tags = new ArrayList<String>();
|
||||
}
|
||||
public void updateTasks(List<HabitItem> tasks) {
|
||||
this.tasks.clear();
|
||||
this.tasks.addAll(tasks);
|
||||
if(isFiltered)
|
||||
this.filterTasks(tags);
|
||||
}
|
||||
public List<HabitItem> getItems() {
|
||||
return isFiltered ? filteredTasks : tasks;
|
||||
}
|
||||
@Override
|
||||
public int getCount() {
|
||||
return isFiltered ? filteredTasks.size() : tasks.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public HabitItem getItem(int pos) {
|
||||
return isFiltered ? this.filteredTasks.get(pos) : this.tasks.get(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int pos) {
|
||||
return pos;
|
||||
}
|
||||
public String getIdString(int id) {
|
||||
Log.d(TAG, "id " + id + " --> " + getItem(id).getText() + " (" + getItem(id).getId() + ")");
|
||||
return this.getItem(id).getId();
|
||||
}
|
||||
@Override
|
||||
public abstract View getView(int position, View convertView, ViewGroup parent);
|
||||
|
||||
protected OnClickListener getOnClickListener() {
|
||||
return new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(v.getParent()!=null) {
|
||||
String direction = upOrDown(v, getItem(((View) v.getParent()).getId()));
|
||||
String id = getIdString(((View) v.getParent()).getId());
|
||||
/*((MainActivityOld) getActivity()).onPreResult();*/
|
||||
Log.d("OMG", "id : " + id + " - " + direction);
|
||||
mAPIHelper.updateTaskDirection(id,direction, new TaskScoringCallback((MainActivity) getActivity()));
|
||||
} else {
|
||||
Crouton.makeText(getActivity(), getActivity().getString(R.string.unknown_error), Style.ALERT).show();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected OnClickListener buyItem = new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if(v.getParent()!=null) {
|
||||
|
||||
HabitItem it = getItem(((View) v.getParent()).getId());
|
||||
if(it instanceof Reward.SpecialReward) {
|
||||
mAPIHelper.buyItem(((Reward.SpecialReward) it),v);
|
||||
} else {
|
||||
Crouton.makeText(getActivity(), getActivity().getString(R.string.unknown_error), Style.ALERT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
protected String upOrDown(View v, HabitItem h) {
|
||||
return v.getId() == R.id.minus ? "down" : "up";
|
||||
}
|
||||
|
||||
public void filterTasks(List<String> tagsIds) {
|
||||
//Unfiltering from a tag already filtered = the other tasks aren't there !!!!
|
||||
if(tagsIds.size()>0) {
|
||||
Log.v(TAG + "_tags", "Start filtering with " + tagsIds.size() + " tags");
|
||||
this.isFiltered=true;
|
||||
this.tags.clear();
|
||||
this.tags.addAll(tagsIds);
|
||||
List<HabitItem> tsks = new ArrayList<HabitItem>();
|
||||
for(HabitItem it: this.tasks) {
|
||||
if(it.getTags().containsAll(tagsIds)) {
|
||||
tsks.add(it);
|
||||
}
|
||||
}
|
||||
this.filteredTasks.clear();
|
||||
this.filteredTasks.addAll(tsks);
|
||||
} else {
|
||||
Log.v(TAG + "_tags", "Stop filtering");
|
||||
this.isFiltered=false;
|
||||
this.tags.clear();
|
||||
this.filteredTasks.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public void setItemChecked(int i, boolean new_status) {
|
||||
if(new_status)
|
||||
checkedItem = i;
|
||||
else
|
||||
checkedItem = -1;
|
||||
}
|
||||
public boolean isItemChecked(int i) {
|
||||
return checkedItem == i;
|
||||
}
|
||||
|
||||
public int getNbItemChecked() {
|
||||
return checkedItem == -1 ? 0 : 1;
|
||||
}
|
||||
|
||||
public int getItemCheckedPos() {
|
||||
return checkedItem;
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Get the color resources depending on a certain score
|
||||
* @param d the score
|
||||
* @return the color resource id
|
||||
*/
|
||||
protected int getColorRes(double d) {
|
||||
if(d<-20)
|
||||
return R.drawable.triangle_worst;
|
||||
if(d<-10)
|
||||
return R.drawable.triangle_worse;
|
||||
if(d<-1)
|
||||
return R.drawable.triangle_bad;
|
||||
if(d<5)
|
||||
return R.drawable.triangle_neutral;
|
||||
if(d<10)
|
||||
return R.drawable.triangle_better;
|
||||
return R.drawable.triangle_best;
|
||||
}
|
||||
|
||||
/**
|
||||
* The callback used by the Contextual ActionBar
|
||||
*/
|
||||
private ActionMode.Callback mActionModeCallback = new android.support.v7.view.ActionMode.Callback() {
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(android.support.v7.view.ActionMode actionMode, Menu menu) {
|
||||
// Inflate our menu from a resource file
|
||||
actionMode.getMenuInflater().inflate(R.menu.select_task, menu);
|
||||
|
||||
// Return true so that the action mode is shown
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(android.support.v7.view.ActionMode actionMode, Menu menu) {
|
||||
// As we do not need to modify the menu before displayed, we return false.
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(android.support.v7.view.ActionMode actionMode, MenuItem menuItem) {
|
||||
// Similar to menu handling in Activity.onOptionsItemSelected()
|
||||
switch (menuItem.getItemId()) {
|
||||
case R.id.action_edit:
|
||||
HabitItem taskToUpdate = mAdapter.getItem(mAdapter.getItemCheckedPos());
|
||||
Bundle b = new Bundle();
|
||||
b.putString("type", getTaskType().toString());
|
||||
b.putInt("pos", mAdapter.getItemCheckedPos());
|
||||
DialogFragment dialog = new AddTaskDialog();
|
||||
dialog.setArguments(b);
|
||||
dialog.show(getChildFragmentManager(), "AddTaskDialog");
|
||||
mActionMode.finish();
|
||||
return true;
|
||||
case R.id.deleteConfirmMenuBT:
|
||||
HabitItem taskToDel = mAdapter.getItem(mAdapter.getItemCheckedPos());
|
||||
//((MainActivity) getActivity()).onPreResult();
|
||||
mAPIHelper.deleteTask(taskToDel, new TaskDeletionCallback((MainActivity) getActivity(), taskToDel));
|
||||
mActionMode.finish();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyActionMode(android.support.v7.view.ActionMode actionMode) {
|
||||
mActionMode = null;
|
||||
SparseBooleanArray checked = mListView.getCheckedItemPositions();
|
||||
for(int i=0;i<checked.size();i++) {
|
||||
if(checked.valueAt(i)) {
|
||||
mListView.setItemChecked(checked.keyAt(i),false);
|
||||
mAdapter.setItemChecked(checked.keyAt(i), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,179 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.ChecklistDialog;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType;
|
||||
import com.magicmicky.habitrpgwrapper.lib.utils.DaysUtils;
|
||||
|
||||
public class DailyFragment extends CardFragment {
|
||||
|
||||
private static final String TITLE = "Dailies";
|
||||
private DailyAdapter adapter=null;
|
||||
private int dayStart=0;
|
||||
@Override
|
||||
public MyAdapter instantiateAdapter(Context c) {
|
||||
if(adapter==null) {
|
||||
List<HabitItem> dailies = new ArrayList<HabitItem>();
|
||||
this.adapter = new DailyAdapter(c,dailies);
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
@Override
|
||||
protected HabitType getTaskType() {
|
||||
return HabitType.daily;
|
||||
}
|
||||
@Override
|
||||
protected String getTitle() {
|
||||
return DailyFragment.TITLE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<HabitItem> filterData(List<HabitItem> items) {
|
||||
List<HabitItem> res = new ArrayList<HabitItem>();
|
||||
for(HabitItem it:items) {
|
||||
if(it instanceof Daily) {
|
||||
res.add(it);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private class DailyAdapter extends MyAdapter {
|
||||
public DailyAdapter(Context c, List<HabitItem> dailies) {
|
||||
super(c,dailies);
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
Daily currentItem = (Daily) this.getItem(position);
|
||||
LayoutInflater inflator = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
if (convertView == null){
|
||||
convertView = inflator.inflate(R.layout.todo, parent, false);
|
||||
}
|
||||
|
||||
convertView.setId(position);
|
||||
CheckBox completed = (CheckBox) convertView.findViewById(R.id.plus);
|
||||
completed.setOnClickListener(this.getOnClickListener());
|
||||
TextView text = (TextView) convertView.findViewById(R.id.TV_title);
|
||||
|
||||
ImageButton checklist = (ImageButton) convertView.findViewById(R.id.BT_checklist);
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.add(Calendar.HOUR_OF_DAY, -getDayStart());
|
||||
int index = c.get(Calendar.DAY_OF_WEEK)-2;
|
||||
if(index<0) {
|
||||
index+=7;
|
||||
}
|
||||
if(currentItem.getRepeat() !=null && DaysUtils.getBooleansFromDays(currentItem.getRepeat()).length >= index && !DaysUtils.getBooleansFromDays(currentItem.getRepeat())[index]) {//What do we say to death? Not today!
|
||||
text.setTypeface(null, Typeface.ITALIC);
|
||||
text.setTextColor(getResources().getColor(R.color.card_light_text));
|
||||
ImageView color_indic = (ImageView) convertView.findViewById(R.id.IV_task_color);
|
||||
color_indic.setImageResource(R.color.transparent);
|
||||
} else {
|
||||
if(!currentItem.isCompleted()) {
|
||||
ImageView color_indic = (ImageView) convertView.findViewById(R.id.IV_task_color);
|
||||
color_indic.setImageDrawable(getResources().getDrawable(getColorRes(currentItem.getValue())));
|
||||
text.setTypeface(null, Typeface.BOLD);
|
||||
} else {
|
||||
ImageView color_indic = (ImageView) convertView.findViewById(R.id.IV_task_color);
|
||||
color_indic.setImageDrawable(getResources().getDrawable(R.drawable.triangle_completed));
|
||||
text.setTypeface(null, Typeface.NORMAL);
|
||||
}
|
||||
text.setTextColor(getResources().getColor(R.color.card_text));
|
||||
}
|
||||
text.setText(currentItem.getText());
|
||||
completed.setChecked(isChecked(currentItem));
|
||||
convertView.setLongClickable(true);
|
||||
|
||||
List<com.magicmicky.habitrpgwrapper.lib.models.tasks.Checklist.ChecklistItem> items =currentItem.getItems();
|
||||
|
||||
if (items != null && !items.isEmpty()) {
|
||||
checklist.setVisibility(View.VISIBLE);
|
||||
checklist.setOnClickListener(openChecklist);
|
||||
} else {
|
||||
checklist.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
if(isItemChecked(position)) {
|
||||
convertView.setBackgroundResource(R.drawable.list_focused_holo);
|
||||
} else {
|
||||
convertView.setBackgroundResource(R.drawable.item_background);
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
private boolean isChecked(Daily task) {
|
||||
/*TODO:Calendar resetTime = new GregorianCalendar();
|
||||
// reset hour, minutes, seconds and millis
|
||||
resetTime.set(Calendar.HOUR_OF_DAY, getDayStart());
|
||||
resetTime.set(Calendar.MINUTE, 0);
|
||||
resetTime.set(Calendar.SECOND, 0);
|
||||
resetTime.set(Calendar.MILLISECOND, 0);
|
||||
Timestamp last= new Timestamp(task.getLastCompleted());
|
||||
//last = 29/05/2013 23:59
|
||||
//date =30/05/2013 00:00
|
||||
if(task.isCompleted() && last.compareTo(new Timestamp(resetTime.getTime().getTime())) < 0) {// if last is before today
|
||||
return false;
|
||||
} else {*/
|
||||
return task.isCompleted();
|
||||
//}
|
||||
}
|
||||
@Override
|
||||
protected String upOrDown(View v, HabitItem h) {
|
||||
boolean isChecked = ((CheckBox) v).isChecked();
|
||||
Calendar now = new GregorianCalendar();
|
||||
((Daily) h).setCompleted(isChecked);
|
||||
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
||||
// ((Daily) h).setLastCompleted(format.format(new Date(now.getTimeInMillis())));
|
||||
//TODO wth is that ?
|
||||
return !isChecked ? "down" : "up";
|
||||
|
||||
}
|
||||
private View.OnClickListener openChecklist = new View.OnClickListener() {
|
||||
@Override
|
||||
|
||||
public void onClick(View v) {
|
||||
|
||||
if(v.getParent() != null && v.getParent().getParent() != null) {
|
||||
|
||||
int position = ((View) v.getParent().getParent()).getId();
|
||||
|
||||
ChecklistDialog dialog = new ChecklistDialog(getActivity(),mAPIHelper,(Daily) getItem(position), null);
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public int getDayStart() {
|
||||
return this.dayStart;
|
||||
}
|
||||
public void setDayStart(int dayStart) {
|
||||
this.dayStart = dayStart;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,102 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Habit;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType;
|
||||
|
||||
public class HabitFragment extends CardFragment{
|
||||
|
||||
private static final String TITLE = "Habits";
|
||||
private HabitAdapter adapter = null;
|
||||
private List<HabitItem> res = new ArrayList<HabitItem>();
|
||||
|
||||
@Override
|
||||
public MyAdapter instantiateAdapter(Context c) {
|
||||
if(adapter==null) {
|
||||
List<HabitItem> habit = new ArrayList<HabitItem>();
|
||||
this.adapter = new HabitAdapter(c,habit);
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
@Override
|
||||
protected String getTitle() {
|
||||
return HabitFragment.TITLE;
|
||||
}
|
||||
@Override
|
||||
protected HabitType getTaskType() {
|
||||
return HabitType.habit;
|
||||
}
|
||||
@Override
|
||||
protected List<HabitItem> filterData(List<HabitItem> items) {
|
||||
res.clear();
|
||||
Log.d("filtering", "filter habit");
|
||||
for(HabitItem it:items) {
|
||||
if(it instanceof Habit) {
|
||||
//Log.d("filter", "" + it.getText());
|
||||
res.add(it);
|
||||
} else {
|
||||
//Log.v("filter",""+it.getText() + " - ");
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
private class HabitAdapter extends MyAdapter {
|
||||
public HabitAdapter(Context c, List<HabitItem> habits) {
|
||||
super(c,habits);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
LayoutInflater inflator = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
if (convertView == null){
|
||||
convertView = inflator.inflate(R.layout.habit, parent, false);
|
||||
}
|
||||
convertView.setId(position);
|
||||
Habit currentItem = (Habit) this.getItem(position);
|
||||
//Log.v("HabitFragment", currentItem.getText());
|
||||
Button habitPlus = (Button) convertView.findViewById(R.id.plus);
|
||||
habitPlus.setOnClickListener(getOnClickListener());
|
||||
Button habitMinus = (Button) convertView.findViewById(R.id.minus);
|
||||
habitMinus.setOnClickListener(getOnClickListener());
|
||||
TextView habit = (TextView) convertView.findViewById(R.id.TV_title);
|
||||
//View color_indic = convertView.findViewById(R.id.V_color_indic);
|
||||
//color_indic.setBackgroundColor(getResources().getColor(getColorRes(currentItem.getValue())));
|
||||
ImageView color_indic = (ImageView) convertView.findViewById(R.id.IV_task_color);
|
||||
color_indic.setImageDrawable(getResources().getDrawable(getColorRes(currentItem.getValue())));
|
||||
habit.setText(currentItem.getText());
|
||||
habitPlus.setVisibility(currentItem.isUp()==true?Button.VISIBLE:Button.GONE);
|
||||
habitMinus.setVisibility(currentItem.isDown()==true?Button.VISIBLE:Button.GONE);
|
||||
if(!currentItem.isUp() || !currentItem.isDown()) {
|
||||
convertView.findViewById(R.id.btnDivider).setVisibility(View.INVISIBLE);
|
||||
} else {
|
||||
convertView.findViewById(R.id.btnDivider).setVisibility(View.VISIBLE);
|
||||
}
|
||||
convertView.setLongClickable(true);
|
||||
if(isItemChecked(position)) {
|
||||
convertView.setBackgroundResource(R.drawable.list_focused_holo);
|
||||
} else {
|
||||
convertView.setBackgroundResource(R.drawable.item_background);
|
||||
}
|
||||
return convertView;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,167 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Reward;
|
||||
|
||||
public class RewardFragment extends CardFragment {
|
||||
|
||||
private static final String TITLE = "Rewards";
|
||||
private RewardAdapter adapter = null;
|
||||
private TextView silver=null;
|
||||
private TextView gold=null;
|
||||
private int g=0,s=0;
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View v = super.onCreateView(inflater, container, savedInstanceState);
|
||||
gold = (TextView)v.findViewById(R.id.gold);
|
||||
gold.setVisibility(View.VISIBLE);
|
||||
gold.setText(g+"");
|
||||
silver = (TextView) v.findViewById(R.id.silver);
|
||||
silver.setVisibility(View.VISIBLE);
|
||||
silver.setText(s+"");
|
||||
ImageView gp = (ImageView) v.findViewById(R.id.IMG_gold);
|
||||
gp.setVisibility(View.VISIBLE);
|
||||
ImageView sp = (ImageView) v.findViewById(R.id.IMG_silver);
|
||||
sp.setVisibility(View.VISIBLE);
|
||||
return v;
|
||||
}
|
||||
|
||||
public void setGold(double gp) {
|
||||
this.g = (int) gp;
|
||||
this.s = (int) ((gp - g)*100);
|
||||
if(this.gold!=null && this.silver !=null) {
|
||||
this.gold.setText(g+"");
|
||||
this.silver.setText(s+"");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected HabitType getTaskType() {
|
||||
return HabitType.reward;
|
||||
}
|
||||
@Override
|
||||
protected String getTitle() {
|
||||
return RewardFragment.TITLE;
|
||||
}
|
||||
@Override
|
||||
protected List<HabitItem> filterData(List<HabitItem> items) {
|
||||
List<HabitItem> res = new ArrayList<HabitItem>();
|
||||
for(HabitItem it:items) {
|
||||
if(it instanceof Reward) {
|
||||
res.add(it);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
@Override
|
||||
public MyAdapter instantiateAdapter(Context c) {
|
||||
if(adapter==null) {
|
||||
List<HabitItem> rews = new ArrayList<HabitItem>();
|
||||
this.adapter = new RewardAdapter(c, rews);
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
|
||||
protected class RewardAdapter extends MyAdapter {
|
||||
|
||||
public RewardAdapter(Context c, List<HabitItem> rews) {
|
||||
super(c, rews);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
LayoutInflater inflator = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
if (convertView == null){
|
||||
convertView = inflator.inflate(R.layout.reward, parent, false);
|
||||
|
||||
}
|
||||
Button price = (Button) convertView.findViewById(R.id.plus);
|
||||
price.setCompoundDrawablesWithIntrinsicBounds(null, null,null,null);//(it.getType(), it.getLevel())), null);
|
||||
TextView reward = (TextView) convertView.findViewById(R.id.TV_title);
|
||||
convertView.setId(position);
|
||||
if(this.getItem(position) instanceof Reward.SpecialReward) {
|
||||
Reward.SpecialReward it = (Reward.SpecialReward) this.getItem(position);
|
||||
convertView.setClickable(false);
|
||||
convertView.setLongClickable(false);
|
||||
//UserPicture usPic = new UserPicture("m", RewardFragment.this.getActivity());
|
||||
//Drawable bmpdrw = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(usPic.drawObject(it.getType(), it.getLevel()), 50, 50, true));
|
||||
|
||||
//price.setCompoundDrawablesWithIntrinsicBounds(null, null, bmpdrw,null);//(it.getType(), it.getLevel())), null);
|
||||
price.setOnClickListener(buyItem);
|
||||
|
||||
} else {
|
||||
convertView.setClickable(true);
|
||||
convertView.setLongClickable(true);
|
||||
//price.setCompoundDrawablesWithIntrinsicBounds(null, null, getResources().getDrawable(R.drawable.gold),null);//(it.getType(), it.getLevel())), null);
|
||||
price.setOnClickListener(getOnClickListener());
|
||||
|
||||
}
|
||||
ATaskLoadImage loader = new ATaskLoadImage(price, getActivity());
|
||||
loader.execute(this.getItem(position));
|
||||
Reward currentItem = (Reward) this.getItem(position);
|
||||
|
||||
reward.setText(currentItem.getText());
|
||||
price.setText((int) currentItem.getValue() + "");
|
||||
if(isItemChecked(position)) {
|
||||
convertView.setBackgroundResource(R.drawable.list_focused_holo);
|
||||
} else {
|
||||
convertView.setBackgroundResource(R.drawable.item_background);
|
||||
}
|
||||
|
||||
return convertView;
|
||||
}
|
||||
}
|
||||
private class ATaskLoadImage extends AsyncTask<HabitItem,Void,Drawable> {
|
||||
private final Button viewToAddCompound;
|
||||
private final Context context;
|
||||
|
||||
public ATaskLoadImage(Button v,Context context) {
|
||||
this.viewToAddCompound = v;
|
||||
this.context=context;
|
||||
}
|
||||
@Override
|
||||
protected Drawable doInBackground(HabitItem... item) {
|
||||
Drawable drw;
|
||||
/*if(item[0] instanceof Reward.SpecialReward) {
|
||||
Reward.SpecialReward it = (Reward.SpecialReward) item[0];
|
||||
UserPicture usPic = new UserPicture("m", RewardFragment.this.getActivity());
|
||||
drw = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(usPic.drawObject(it.getType(), it.getLevel()), dipToPixels(context,30), dipToPixels(context,30), true));
|
||||
|
||||
} else {
|
||||
*/ drw = getResources().getDrawable(R.drawable.gold);
|
||||
//}
|
||||
return drw;
|
||||
}
|
||||
@Override
|
||||
protected void onPostExecute(Drawable d) {
|
||||
this.viewToAddCompound.setCompoundDrawablesWithIntrinsicBounds(null,null,d,null);
|
||||
}
|
||||
private int dipToPixels(Context context, float dipValue) {
|
||||
DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||
return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.habitrpg.android.habitica.ChecklistDialog;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.Daily;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitItem;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.HabitType;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.tasks.ToDo;
|
||||
|
||||
public class ToDoFragment extends CardFragment {
|
||||
private static final String TITLE = "To do";
|
||||
private ToDoAdapter adapter = null;
|
||||
|
||||
@Override
|
||||
public MyAdapter instantiateAdapter(Context c) {
|
||||
if (adapter == null) {
|
||||
List<HabitItem> todos = new ArrayList<HabitItem>();
|
||||
this.adapter = new ToDoAdapter(c, todos);
|
||||
}
|
||||
return adapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HabitType getTaskType() {
|
||||
return HabitType.todo;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTitle() {
|
||||
return ToDoFragment.TITLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<HabitItem> filterData(List<HabitItem> items) {
|
||||
List<HabitItem> res = new ArrayList<HabitItem>();
|
||||
for (HabitItem it : items) {
|
||||
if (it instanceof ToDo) {
|
||||
if (((ToDo) it).isCompleted()) {
|
||||
|
||||
} else {
|
||||
res.add(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
protected class ToDoAdapter extends MyAdapter {
|
||||
public ToDoAdapter(Context c, List<HabitItem> todos) {
|
||||
super(c, todos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
LayoutInflater inflator = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
if (convertView == null) {
|
||||
convertView = inflator.inflate(R.layout.todo, parent, false);
|
||||
}
|
||||
convertView.setId(position);
|
||||
ToDo currentItem = (ToDo) this.getItem(position);
|
||||
ImageView color_indic = (ImageView) convertView.findViewById(R.id.IV_task_color);
|
||||
color_indic.setImageDrawable(getResources().getDrawable(getColorRes(currentItem.getValue())));
|
||||
CheckBox completed = (CheckBox) convertView.findViewById(R.id.plus);
|
||||
completed.setOnClickListener(this.getOnClickListener());
|
||||
TextView text = (TextView) convertView.findViewById(R.id.TV_title);
|
||||
text.setText(currentItem.getText());
|
||||
completed.setChecked(currentItem.isCompleted());
|
||||
convertView.setLongClickable(true);
|
||||
|
||||
ImageButton checklist = (ImageButton) convertView.findViewById(R.id.BT_checklist);
|
||||
|
||||
List<com.magicmicky.habitrpgwrapper.lib.models.tasks.Checklist.ChecklistItem> items =currentItem.getItems();
|
||||
|
||||
|
||||
if (items != null && !items.isEmpty()) {
|
||||
checklist.setVisibility(View.VISIBLE);
|
||||
checklist.setOnClickListener(openChecklist);
|
||||
} else {
|
||||
checklist.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
|
||||
if (isItemChecked(position)) {
|
||||
convertView.setBackgroundResource(R.drawable.list_focused_holo);
|
||||
} else {
|
||||
convertView.setBackgroundResource(R.drawable.item_background);
|
||||
}
|
||||
|
||||
return convertView;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String upOrDown(View v, HabitItem h) {
|
||||
boolean isChecked = ((CheckBox) v).isChecked();
|
||||
((ToDo) h).setCompleted(isChecked);
|
||||
return !isChecked ? "down" : "up";
|
||||
|
||||
}
|
||||
|
||||
private View.OnClickListener openChecklist = new View.OnClickListener() {
|
||||
@Override
|
||||
|
||||
public void onClick(View v) {
|
||||
|
||||
if (v.getParent() != null && v.getParent().getParent() != null) {
|
||||
|
||||
int position = ((View) v.getParent().getParent()).getId();
|
||||
|
||||
ChecklistDialog dialog = new ChecklistDialog(getActivity(), mAPIHelper, (ToDo) getItem(position), null);
|
||||
|
||||
dialog.show();
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue