Rewrite activity to fragment
This commit is contained in:
parent
f5edf67c15
commit
d6710a5406
@ -42,6 +42,7 @@ public abstract class BaseActivity
|
||||
private ArrayList<String> stringArrayList;
|
||||
private ListViewAdapter adapter;
|
||||
private SharingFragment sharingFragment;
|
||||
private Fragment userListFragment;
|
||||
|
||||
|
||||
@Override
|
||||
@ -52,6 +53,7 @@ public abstract class BaseActivity
|
||||
navigationView = findViewById(R.id.navigation);
|
||||
navigationView.setOnNavigationItemSelectedListener(this);
|
||||
sharingFragment = new SharingFragment();
|
||||
userListFragment = new UsersListActivity();
|
||||
|
||||
|
||||
}
|
||||
@ -73,7 +75,7 @@ public abstract class BaseActivity
|
||||
|
||||
private void setUpNav() {
|
||||
|
||||
drawerLayout = (DrawerLayout) findViewById(R.id.activity_container);
|
||||
drawerLayout = findViewById(R.id.activity_container);
|
||||
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawerLayout.addDrawerListener(actionBarDrawerToggle);
|
||||
|
||||
@ -165,16 +167,20 @@ public abstract class BaseActivity
|
||||
|
||||
navigationView.postDelayed(() -> {
|
||||
int itemId = item.getItemId();
|
||||
|
||||
if (itemId == R.id.nav_map) {
|
||||
removeFragment(sharingFragment);
|
||||
removeFragment(userListFragment);
|
||||
// startActivity(new Intent(this, MapActivity.class));
|
||||
} else if (itemId == R.id.nav_profile) {
|
||||
// startActivity(new Intent(this, ProfileActivity.class));
|
||||
setFragment(sharingFragment);
|
||||
removeFragment(userListFragment);
|
||||
|
||||
} else if (itemId == R.id.nav_user_list) {
|
||||
removeFragment(sharingFragment);
|
||||
startActivity(new Intent(this, UsersListActivity.class));
|
||||
setFragment(userListFragment);
|
||||
//startActivity(new Intent(this, UsersListActivity.class));
|
||||
}
|
||||
//finish();
|
||||
}, 300);
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@ -21,11 +22,11 @@ import java.util.Objects;
|
||||
|
||||
public class ListViewAdapter extends ArrayAdapter<String> {
|
||||
|
||||
private UsersListActivity activity;
|
||||
private Context activity;
|
||||
private List<String> friendList;
|
||||
private List<String> searchList;
|
||||
|
||||
public ListViewAdapter(UsersListActivity context, int resource, List<String> objects) {
|
||||
public ListViewAdapter(Context context, int resource, List<String> objects) {
|
||||
super(context, resource, objects);
|
||||
this.activity = context;
|
||||
this.friendList = objects;
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Fragment;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
@ -14,6 +14,7 @@ import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
@ -44,7 +45,9 @@ import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
public class UsersListActivity extends BaseActivity {
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
public class UsersListActivity extends Fragment {
|
||||
private static final String TAG = UsersListActivity.class.getSimpleName();
|
||||
@BindView(R.id.coordinator_layout)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@ -52,35 +55,43 @@ public class UsersListActivity extends BaseActivity {
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.txt_empty_notes_view)
|
||||
TextView noNotesView;
|
||||
|
||||
private UserService userService;
|
||||
private TutorTabApi tutorTabService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private TutorsAdapter mAdapter;
|
||||
private List<User> tutorsList = new ArrayList<>();
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.N)
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.users_list);
|
||||
ButterKnife.bind(this);
|
||||
public UsersListActivity() {
|
||||
}
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
mAdapter = new TutorsAdapter(getActivity().getApplicationContext(), tutorsList);
|
||||
View view = inflater.inflate(R.layout.users_list, container, false);
|
||||
view.setBackgroundColor(getResources().getColor(android.R.color.white));
|
||||
return view;
|
||||
}
|
||||
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
userService = ApiClient.getClient(getApplicationContext())
|
||||
.create(UserService.class);
|
||||
|
||||
tutorTabService = ApiClient.getClient(getApplicationContext())
|
||||
tutorTabService = ApiClient.getClient(getActivity().getApplicationContext())
|
||||
.create(TutorTabApi.class);
|
||||
|
||||
mAdapter = new TutorsAdapter(this, tutorsList);
|
||||
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getApplicationContext());
|
||||
|
||||
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext());
|
||||
recyclerView.setLayoutManager(mLayoutManager);
|
||||
recyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||
recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16));
|
||||
recyclerView.addItemDecoration(new MyDividerItemDecoration(getActivity().getApplicationContext(), LinearLayoutManager.VERTICAL, 16));
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
|
||||
fetchAllTutors();
|
||||
|
||||
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(this,
|
||||
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity().getApplicationContext(),
|
||||
recyclerView, new RecyclerTouchListener.ClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, final int position) {
|
||||
@ -93,11 +104,12 @@ public class UsersListActivity extends BaseActivity {
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
private void showNoteDialog(final boolean shouldUpdate, final User user, final int position) {
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getActivity().getApplicationContext());
|
||||
View view = layoutInflaterAndroid.inflate(R.layout.note_dialog, null);
|
||||
|
||||
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this);
|
||||
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(getActivity().getApplicationContext());
|
||||
alertDialogBuilderUserInput.setView(view);
|
||||
|
||||
alertDialogBuilderUserInput.setNegativeButton(R.string.cancel, (dialog, id) -> {
|
||||
@ -128,7 +140,7 @@ public class UsersListActivity extends BaseActivity {
|
||||
userEmail.setText(String.format("%s: %s", getString(R.string.userEmail), tutorTabViewModel.getEmailTutorTab()));
|
||||
userNote.setText(String.format("%s: %s", getString(R.string.userNote), tutorTabViewModel.getNote()));
|
||||
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(UsersListActivity.this,
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity().getApplicationContext(),
|
||||
android.R.layout.simple_list_item_activated_1, dutyHoursList);
|
||||
|
||||
userDutyHours.setAdapter(arrayAdapter);
|
||||
@ -172,10 +184,11 @@ public class UsersListActivity extends BaseActivity {
|
||||
.subscribeWith(new DisposableSingleObserver<List<User>>() {
|
||||
@Override
|
||||
public void onSuccess(List<User> users) {
|
||||
toggleEmptyNotes();
|
||||
tutorsList.clear();
|
||||
tutorsList.addAll(users);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
toggleEmptyNotes();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -214,21 +227,30 @@ public class UsersListActivity extends BaseActivity {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
|
||||
protected int getContentViewId() {
|
||||
return R.layout.users_list;
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
fetchAllTutors();
|
||||
Log.e(TAG,"onResume");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
Log.e(TAG,"onPause");
|
||||
|
||||
protected int getNavigationMenuItemId() {
|
||||
return R.id.nav_user_list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
Log.e(TAG,"onStop");
|
||||
}
|
||||
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
|
@ -1,21 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/coordinator_layout"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/coordinator_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.UsersListActivity">
|
||||
<!--
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
-->
|
||||
|
||||
|
||||
<include layout="@layout/users_list_main" />
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
||||
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
|
||||
<RelativeLayout 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"
|
||||
|
Loading…
Reference in New Issue
Block a user