Skip to content

Commit

Permalink
Lesson 4: Cleaning up onViewCreated
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseBuss committed May 29, 2020
1 parent 7d19780 commit a0deb72
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 118 deletions.
1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 0 additions & 39 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
package com.example.avjindersinghsekhon.minimaltodo.AddToDo;

import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;

import com.amulyakhare.textdrawable.util.ColorGenerator;
import com.example.avjindersinghsekhon.minimaltodo.AppDefault.AppDefaultActivity;
import com.example.avjindersinghsekhon.minimaltodo.R;
import com.example.avjindersinghsekhon.minimaltodo.Utility.ToDoItem;

public class AddToDoActivity extends AppDefaultActivity {
public static final String TODOITEM = "com.avjindersinghsekhon.com.avjindersinghsekhon.minimaltodo.MainActivity";

public static void startForResult(Fragment fragment, int requestCode) {
Intent newTodo = new Intent(fragment.getContext(), AddToDoActivity.class);
ToDoItem item = new ToDoItem("","", false, null);
int color = ColorGenerator.MATERIAL.getRandomColor();
item.setTodoColor(color);
newTodo.putExtra(TODOITEM, item);

fragment.startActivityForResult(newTodo, requestCode);
}
@SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public class MainFragment extends AppDefaultFragment {
private FloatingActionButton mAddToDoItemFAB;
private ArrayList<ToDoItem> mToDoItemsArrayList;
private CoordinatorLayout mCoordLayout;
public static final String TODOITEM = "com.avjindersinghsekhon.com.avjindersinghsekhon.minimaltodo.MainActivity";
private MainFragment.BasicListAdapter adapter;
private static final int REQUEST_ID_TODO_ITEM = 100;
private ToDoItem mJustDeletedToDoItem;
Expand Down Expand Up @@ -91,98 +90,52 @@ public class MainFragment extends AppDefaultFragment {
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
app = (AnalyticsApplication) getActivity().getApplication();
// CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
// .setDefaultFontPath("fonts/Aller_Regular.tff").setFontAttrId(R.attr.fontPath).build());

//We recover the theme we've set and setTheme accordingly
theme = getActivity().getSharedPreferences(THEME_PREFERENCES, MODE_PRIVATE).getString(THEME_SAVED, LIGHTTHEME);

if (theme.equals(LIGHTTHEME)) {
mTheme = R.style.CustomStyle_LightTheme;
} else {
mTheme = R.style.CustomStyle_DarkTheme;
}
this.getActivity().setTheme(mTheme);

super.onCreate(savedInstanceState);


SharedPreferences sharedPreferences = getActivity().getSharedPreferences(SHARED_PREF_DATA_SET_CHANGED, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(CHANGE_OCCURED, false);
editor.apply();
setTheme();
setChange();

storeRetrieveData = new StoreRetrieveData(getContext(), FILENAME);
mToDoItemsArrayList = getLocallyStoredData(storeRetrieveData);
adapter = new MainFragment.BasicListAdapter(mToDoItemsArrayList);
setAlarms();


// adapter.notifyDataSetChanged();
// storeRetrieveData = new StoreRetrieveData(this, FILENAME);
//
// try {
// mToDoItemsArrayList = storeRetrieveData.loadFromFile();
//// Log.d("OskarSchindler", "Arraylist Length: "+mToDoItemsArrayList.size());
// } catch (IOException | JSONException e) {
//// Log.d("OskarSchindler", "IOException received");
// e.printStackTrace();
// }
//
// if(mToDoItemsArrayList==null){
// mToDoItemsArrayList = new ArrayList<>();
// }
//

// mToDoItemsArrayList = new ArrayList<>();
// makeUpItems(mToDoItemsArrayList, testStrings.length);


mCoordLayout = (CoordinatorLayout) view.findViewById(R.id.myCoordinatorLayout);
mAddToDoItemFAB = (FloatingActionButton) view.findViewById(R.id.addToDoItemFAB);
mCoordLayout = view.findViewById(R.id.myCoordinatorLayout);
mAddToDoItemFAB = view.findViewById(R.id.addToDoItemFAB);

mAddToDoItemFAB.setOnClickListener(new View.OnClickListener() {

@SuppressWarnings("deprecation")
@Override
public void onClick(View v) {
app.send(this, "Action", "FAB pressed");
Intent newTodo = new Intent(getContext(), AddToDoActivity.class);
ToDoItem item = new ToDoItem("","", false, null);
int color = ColorGenerator.MATERIAL.getRandomColor();
item.setTodoColor(color);
//noinspection ResourceType
// String color = getResources().getString(R.color.primary_ligher);
newTodo.putExtra(TODOITEM, item);
// View decorView = getWindow().getDecorView();
// View navView= decorView.findViewById(android.R.id.navigationBarBackground);
// View statusView = decorView.findViewById(android.R.id.statusBarBackground);
// Pair<View, String> navBar ;
// if(navView!=null){
// navBar = Pair.create(navView, navView.getTransitionName());
// }
// else{
// navBar = null;
// }
// Pair<View, String> statusBar= Pair.create(statusView, statusView.getTransitionName());
// ActivityOptions options;
// if(navBar!=null){
// options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, navBar, statusBar);
// }
// else{
// options = ActivityOptions.makeSceneTransitionAnimation(MainActivity.this, statusBar);
// }

// startActivity(new Intent(MainActivity.this, TestLayout.class), options.toBundle());
// startActivityForResult(newTodo, REQUEST_ID_TODO_ITEM, options.toBundle());

startActivityForResult(newTodo, REQUEST_ID_TODO_ITEM);
AddToDoActivity.startForResult(MainFragment.this, REQUEST_ID_TODO_ITEM);
}
});

initRecyclerView(view);
}

private void setTheme() {
theme = getActivity().getSharedPreferences(THEME_PREFERENCES, MODE_PRIVATE).getString(THEME_SAVED, LIGHTTHEME);

if (theme.equals(LIGHTTHEME)) {
mTheme = R.style.CustomStyle_LightTheme;
} else {
mTheme = R.style.CustomStyle_DarkTheme;
}
this.getActivity().setTheme(mTheme);
}

private void setChange() {
SharedPreferences sharedPreferences = getActivity().getSharedPreferences(SHARED_PREF_DATA_SET_CHANGED, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(CHANGE_OCCURED, false);
editor.apply();
}

// mRecyclerView = (RecyclerView)findViewById(R.id.toDoRecyclerView);
mRecyclerView = (RecyclerViewEmptySupport) view.findViewById(R.id.toDoRecyclerView);
private void initRecyclerView(View view) {

mRecyclerView = view.findViewById(R.id.toDoRecyclerView);
if (theme.equals(LIGHTTHEME)) {
mRecyclerView.setBackgroundColor(getResources().getColor(R.color.primary_lightest));
}
Expand Down Expand Up @@ -217,9 +170,6 @@ public void hide() {


mRecyclerView.setAdapter(adapter);
// setUpTransitions();


}

public static ArrayList<ToDoItem> getLocallyStoredData(StoreRetrieveData storeRetrieveData) {
Expand Down

0 comments on commit a0deb72

Please sign in to comment.