Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#4[30m]. Refactor NavDrawerActivity and ReportActivity.
  • Loading branch information
Evgenii Kanivets committed Jan 26, 2016
commit 7ac618b4b1ebc87581f972b50e285c0e470e45f5
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
android:theme="@style/Theme.Default">
<activity
android:name=".activity.ReportActivity"
android:label="@string/report"
android:screenOrientation="portrait"
android:theme="@style/Theme.Default" />
<activity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.blogspot.e_kanivets.moneytracker.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;

import com.blogspot.e_kanivets.moneytracker.R;
import com.blogspot.e_kanivets.moneytracker.activity.base.BaseActivity;
import com.blogspot.e_kanivets.moneytracker.fragment.AccountsFragment;
import com.blogspot.e_kanivets.moneytracker.fragment.ExportFragment;
import com.blogspot.e_kanivets.moneytracker.fragment.NavigationDrawerFragment;
import com.blogspot.e_kanivets.moneytracker.fragment.RecordsFragment;
import com.blogspot.e_kanivets.moneytracker.util.PrefUtils;

public class NavDrawerActivity extends AppCompatActivity
public class NavDrawerActivity extends BaseActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
@SuppressWarnings("unused")
private static final String TAG = "NavDrawerActivity";
Expand All @@ -30,20 +29,26 @@ public class NavDrawerActivity extends AppCompatActivity
private CharSequence mTitle;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nav_drawer);
protected int getContentViewId() {
return R.layout.activity_nav_drawer;
}

/* Increment launch count */
@Override
protected boolean initData() {
PrefUtils.addLaunchCount();
return true;
}

@Override
protected void initViews() {
super.initViews();

mNavigationDrawerFragment = (NavigationDrawerFragment)
getSupportFragmentManager().findFragmentById(R.id.navigation_drawer);
mTitle = getTitle();

// Set up the drawer.
mNavigationDrawerFragment.setUp(
R.id.navigation_drawer,
mNavigationDrawerFragment.setUp(R.id.navigation_drawer,
(DrawerLayout) findViewById(R.id.drawer_layout));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package com.blogspot.e_kanivets.moneytracker.activity;

import android.app.Activity;
import android.os.Bundle;
import android.util.Pair;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.widget.ExpandableListView;
import android.widget.ListView;

import com.blogspot.e_kanivets.moneytracker.R;
import com.blogspot.e_kanivets.moneytracker.activity.base.BaseActivity;
import com.blogspot.e_kanivets.moneytracker.adapter.ExpandableListReportAdapter;
import com.blogspot.e_kanivets.moneytracker.adapter.ReportItemAdapter;
import com.blogspot.e_kanivets.moneytracker.controller.RecordController;
Expand All @@ -25,46 +23,46 @@
import java.util.List;
import java.util.Map;

public class ReportActivity extends Activity {
import butterknife.Bind;

public class ReportActivity extends BaseActivity {
@SuppressWarnings("unused")
private static final String TAG = "ReportActivity";

public static final String KEY_PERIOD = "key_period";

private Activity activity;
private Report report;

private ListView listView;
private ExpandableListView expandableListView;
@Bind(R.id.list_view)
ListView listView;
@Bind(R.id.exp_list_view)
ExpandableListView expandableListView;

private RecordController recordController;
private Period period;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_report);
protected int getContentViewId() {
return R.layout.activity_report;
}

@Override
protected boolean initData() {
super.initData();

recordController = new RecordController(new DbHelper(ReportActivity.this));

period = getIntent().getParcelableExtra(KEY_PERIOD);
if (period == null) {
finish();
return;
}

activity = this;
report = new Report(recordController.getRecords(period));

initViews();
return period != null;
}

private void initViews() {
listView = (ListView) findViewById(R.id.listView);
expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
@Override
protected void initViews() {
super.initViews();

listView.setAdapter(new ReportItemAdapter(activity,
listView.setAdapter(new ReportItemAdapter(ReportActivity.this,
new Report(recordController.getRecords(period)).getReportList()));

/* Scroll list to bottom only once at start */
Expand Down Expand Up @@ -97,10 +95,10 @@ private void initExpandableListView() {
Map<String, String> m;

/* Fill the group list */
groupData = new ArrayList<Map<String, String>>();
groupData = new ArrayList<>();
for (Pair<String, Integer> item : report.getReportList()) {
/* Fill up attribute names for each group */
m = new HashMap<String, String>();
m = new HashMap<>();
m.put(Constants.TITLE_PARAM_NAME, item.first);
m.put(Constants.PRICE_PARAM_NAME, Integer.toString(item.second));

Expand All @@ -113,10 +111,10 @@ private void initExpandableListView() {
int groupTo[] = new int[]{R.id.tv_category, R.id.tv_total};

/* Create list for childDataItems */
childData = new ArrayList<List<Map<String, String>>>();
childData = new ArrayList<>();

for (Map<String, String> group : groupData) {
childDataItem = new ArrayList<Map<String, String>>();
childDataItem = new ArrayList<>();
/* Fill up attribute names for each child item */
for (Record record : report.getSummaryRecordList()) {
if (record.getCategory().equals(group.get(Constants.TITLE_PARAM_NAME))) {
Expand All @@ -125,7 +123,7 @@ private void initExpandableListView() {
price *= -1;
}

m = new HashMap<String, String>();
m = new HashMap<>();
m.put(Constants.TITLE_PARAM_NAME, record.getTitle());
m.put(Constants.PRICE_PARAM_NAME, Integer.toString(price));

Expand All @@ -144,7 +142,7 @@ private void initExpandableListView() {

expandableListView.addFooterView(getSummaryReportView(report.getSummaryReportList()));
expandableListView.setAdapter(new ExpandableListReportAdapter(
activity,
ReportActivity.this,
groupData,
R.layout.view_report_item_exp,
groupFrom,
Expand All @@ -159,7 +157,7 @@ private void initExpandableListView() {
private View getSummaryReportView(List<Pair<String, Integer>> summaryReportList) {
ViewGroup viewGroup = (ViewGroup) getLayoutInflater().inflate(R.layout.view_summary_report, null);

ReportItemAdapter adapter = new ReportItemAdapter(activity, summaryReportList);
ReportItemAdapter adapter = new ReportItemAdapter(ReportActivity.this, summaryReportList);

for (int i = 0; i < adapter.getCount(); i++) {
viewGroup.addView(adapter.getView(i, null, null));
Expand Down
32 changes: 4 additions & 28 deletions app/src/main/res/layout/activity_report.xml
Original file line number Diff line number Diff line change
@@ -1,46 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/light_grey">

<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/yellow_light">

<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/report_caps"
android:background="@color/yellow_light"
android:textColor="@color/white"
android:gravity="center"
android:id="@+id/tv_title"
android:layout_weight="1" />

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/selector_report"
android:padding="15dp" />
</LinearLayout>
android:background="@color/light_grey"
android:orientation="vertical">

<ListView
android:id="@+id/list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listView"
android:layout_gravity="center_horizontal"
android:visibility="gone" />

<ExpandableListView
android:id="@+id/exp_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/expandableListView"
android:layout_gravity="center_horizontal" />

</LinearLayout>