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[1h]. Refactor all fragments.
  • Loading branch information
Evgenii Kanivets committed Jan 27, 2016
commit ce26f1ecce5dbc0d5394cf1350ae98d6babaf310
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@
import com.blogspot.e_kanivets.moneytracker.fragment.RecordsFragment;
import com.blogspot.e_kanivets.moneytracker.util.PrefUtils;

import butterknife.Bind;

public class NavDrawerActivity extends BaseActivity
implements NavigationDrawerFragment.NavigationDrawerCallbacks {
@SuppressWarnings("unused")
private static final String TAG = "NavDrawerActivity";

@Bind(R.id.drawer_layout)
DrawerLayout drawerLayout;

/**
* Fragment managing the behaviors, interactions and presentation of the navigation drawer.
*/
Expand Down Expand Up @@ -48,8 +54,7 @@ protected void initViews() {
mTitle = getTitle();

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ protected void initViews() {
accounts.add(account.getTitle());
}

spinnerAccount = (Spinner) findViewById(R.id.spinner_account);
spinnerAccount.setAdapter(new ArrayAdapter<>(AddRecordBaseActivity.this,
android.R.layout.simple_list_item_1, accounts));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,20 @@
import com.blogspot.e_kanivets.moneytracker.controller.AccountController;
import com.blogspot.e_kanivets.moneytracker.helper.DbHelper;

/**
* A simple {@link Fragment} subclass.
* Use the {@link AccountsFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class AccountsFragment extends Fragment implements View.OnClickListener {
import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class AccountsFragment extends Fragment {
public static final String TAG = "AccountsFragment";

private static final int REQUEST_ADD_ACCOUNT = 1;

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

private AccountController accountController;

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @return A new instance of fragment AccountsFragment.
*/
public static AccountsFragment newInstance() {
AccountsFragment fragment = new AccountsFragment();
Bundle args = new Bundle();
Expand Down Expand Up @@ -79,23 +73,15 @@ public void onAttach(Activity activity) {
((NavDrawerActivity) activity).onSectionAttached(TAG);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_add_account:
Intent intent = new Intent(getActivity(), AddAccountActivity.class);
startActivityForResult(intent, REQUEST_ADD_ACCOUNT);
break;

default:
break;
}
@OnClick(R.id.btn_add_account)
public void addAccount() {
Intent intent = new Intent(getActivity(), AddAccountActivity.class);
startActivityForResult(intent, REQUEST_ADD_ACCOUNT);
}

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);

getActivity().getMenuInflater().inflate(R.menu.menu_account, menu);
}

Expand Down Expand Up @@ -136,9 +122,7 @@ private void update() {

private void initViews(View rootView) {
if (rootView != null) {
listView = (ListView) rootView.findViewById(R.id.list_view);

rootView.findViewById(R.id.btn_add_account).setOnClickListener(this);
ButterKnife.bind(this, rootView);

listView.setAdapter(new AccountAdapter(getActivity(), accountController.getAccounts()));
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
Expand All @@ -150,8 +134,6 @@ private void initViews(View rootView) {

private void initActionBar() {
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setCustomView(null);
}
if (actionBar != null) actionBar.setCustomView(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,12 @@
import java.io.PrintWriter;
import java.util.List;

/**
* A simple {@link Fragment} subclass.
* Use the {@link ExportFragment#newInstance} factory method to
* create an instance of this fragment.
*/
public class ExportFragment extends Fragment implements View.OnClickListener {
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ExportFragment extends Fragment {
public static final String TAG = "ExportFragment";

/**
* Use this factory method to create a new instance of
* this fragment using the provided parameters.
*
* @return A new instance of fragment ExportFragment.
*/
public static ExportFragment newInstance() {
ExportFragment fragment = new ExportFragment();
Bundle args = new Bundle();
Expand All @@ -46,18 +38,9 @@ public ExportFragment() {
// Required empty public constructor
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

if (getArguments() != null) {
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View rootView = inflater.inflate(R.layout.fragment_export, container, false);
initViews(rootView);
initActionBar();
Expand All @@ -71,22 +54,8 @@ public void onAttach(Activity activity) {
((NavDrawerActivity) activity).onSectionAttached(TAG);
}

@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_export:
exportRecords();
break;

default:
break;
}
}

private void initViews(View rootView) {
if (rootView != null) {
rootView.findViewById(R.id.btn_export).setOnClickListener(this);
}
if (rootView != null) ButterKnife.bind(this, rootView);
}

private void initActionBar() {
Expand All @@ -96,7 +65,8 @@ private void initActionBar() {
}
}

private void exportRecords() {
@OnClick(R.id.btn_export)
public void exportRecords() {
RecordController recordController = new RecordController(new DbHelper(getActivity()));
List<String> records = recordController.getRecordsForExport(0, Long.MAX_VALUE);

Expand Down
Loading