fragment with background

This commit is contained in:
Domagalski 2018-10-22 01:01:06 +02:00
parent 091b714b18
commit d60a3c413c
3 changed files with 76 additions and 99 deletions

View File

@ -29,7 +29,7 @@
</value> </value>
</option> </option>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8 (1)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -6,6 +6,7 @@ import android.app.FragmentTransaction;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.design.widget.BottomNavigationView; import android.support.design.widget.BottomNavigationView;
@ -39,7 +40,6 @@ import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import android.util.Log; import android.util.Log;
import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.geometry.LatLng; import com.mapbox.mapboxsdk.geometry.LatLng;
import com.uam.wmi.findmytutor.ListViewAdapter;
import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService; import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.PrefUtils;
@ -62,7 +62,7 @@ import io.reactivex.schedulers.Schedulers;
public class MainActivity extends AppCompatActivity implements public class MainActivity extends AppCompatActivity implements
OnMapReadyCallback { OnMapReadyCallback {
private BottomNavigationView mMainNav; private BottomNavigationView mMainNav;
private FrameLayout mMainFrame; private FrameLayout mMainFrame;
@ -88,11 +88,7 @@ OnMapReadyCallback {
private CoordinateService coordinateService; private CoordinateService coordinateService;
private CompositeDisposable disposable = new CompositeDisposable(); private CompositeDisposable disposable = new CompositeDisposable();
private Runnable mStatusChecker;
// 4 search
private ListView listView;
private ArrayList<String> stringArrayList;
private ListViewAdapter adapter;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -101,6 +97,17 @@ OnMapReadyCallback {
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE); final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
final String authToken = sharedPref.getString("authToken",null); final String authToken = sharedPref.getString("authToken",null);
mStatusChecker = new Runnable() {
@Override
public void run() {
try{
fetchTopCoords();
} finally {
mHandler.postDelayed(mStatusChecker, mInterval);
}
}
};
coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg"); coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg");
mHandler = new Handler(); mHandler = new Handler();
@ -141,28 +148,10 @@ OnMapReadyCallback {
} }
Runnable mStatusChecker = new Runnable() {
@Override
public void run() {
try{
fetchTopCoords();
} finally {
mHandler.postDelayed(mStatusChecker, mInterval);
}
}
};
private void configureconfigureNavigationDrawer() { private void configureconfigureNavigationDrawer() {
listView = findViewById(R.id.list_item);
Toolbar toolbar = findViewById(R.id.toolbar_main); Toolbar toolbar = findViewById(R.id.toolbar_main);
setSupportActionBar(toolbar); setSupportActionBar(toolbar);
setData();
adapter = new ListViewAdapter(this, R.layout.item_listview, stringArrayList);
listView.setAdapter(adapter);
listView.setOnItemClickListener((parent, view, position, id) -> Toast.makeText(MainActivity.this, (String)parent.getItemAtPosition(position), Toast.LENGTH_SHORT).show());
drawerLayout = findViewById(R.id.drawer_layout); drawerLayout = findViewById(R.id.drawer_layout);
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
@ -175,7 +164,6 @@ OnMapReadyCallback {
actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true); actionBar.setHomeButtonEnabled(true);
} }
} }
private void setFragment(Fragment fragment) { private void setFragment(Fragment fragment) {
@ -200,7 +188,7 @@ OnMapReadyCallback {
profileFragment = new ProfileFragment(); profileFragment = new ProfileFragment();
// Default frag here // Default frag here
setFragment(mapFragment); // setFragment(mapFragment);
mMainNav.setSelectedItemId(R.id.nav_map); mMainNav.setSelectedItemId(R.id.nav_map);
/* code below is resposible for changing colours of tabs in main tab menu */ /* code below is resposible for changing colours of tabs in main tab menu */
@ -209,13 +197,12 @@ OnMapReadyCallback {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.nav_map: case R.id.nav_map:
// setFragment(mapFragment); // setFragment(mapFragment);
setFragment(sharingFragment);
return true; return true;
case R.id.nav_notif: case R.id.nav_notif:
setFragment(notificationFragment); setFragment(notificationFragment);
return true; return true;
case R.id.nav_profile: case R.id.nav_profile:
setFragment(profileFragment); setFragment(sharingFragment);
return true; return true;
default: default:
return false; return false;
@ -240,25 +227,6 @@ OnMapReadyCallback {
}); });
} }
// mock 4 search bar
private void setData() {
stringArrayList = new ArrayList<>();
stringArrayList.add("Quynh Trang");
stringArrayList.add("Hoang Bien");
stringArrayList.add("Duc Tuan");
stringArrayList.add("Dang Thanh");
stringArrayList.add("Xuan Luu");
stringArrayList.add("Phan Thanh");
stringArrayList.add("Kim Kien");
stringArrayList.add("Ngo Trang");
stringArrayList.add("Thanh Ngan");
stringArrayList.add("Nguyen Duong");
stringArrayList.add("Quoc Cuong");
stringArrayList.add("Tran Ha");
stringArrayList.add("Vu Danh");
stringArrayList.add("Minh Meo");
}
@Override @Override
public boolean onCreateOptionsMenu( Menu menu) { public boolean onCreateOptionsMenu( Menu menu) {
getMenuInflater().inflate( R.menu.menu_main, menu); getMenuInflater().inflate( R.menu.menu_main, menu);
@ -274,16 +242,16 @@ OnMapReadyCallback {
@Override @Override
public boolean onQueryTextChange(String newText) { public boolean onQueryTextChange(String newText) {
if (TextUtils.isEmpty(newText)) { if (TextUtils.isEmpty(newText)) {
adapter.filter(""); // adapter.filter("");
listView.clearTextFilter(); // listView.clearTextFilter();
} else { } else {
adapter.filter(newText); // adapter.filter(newText);
} }
return true; return true;
} }
}); });
return true; return true;
} }
@ -376,7 +344,7 @@ OnMapReadyCallback {
private void fetchTopCoords() { private void fetchTopCoords() {
disposable.add( disposable.add(
// coordinateService.getTopCoordinates() // coordinateService.getTopCoordinates()
coordinateService.getOnlineCoordinates() coordinateService.getOnlineCoordinates()
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
@ -428,6 +396,12 @@ OnMapReadyCallback {
} }
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
@ -464,12 +438,6 @@ OnMapReadyCallback {
mHandler.removeCallbacks(mStatusChecker); mHandler.removeCallbacks(mStatusChecker);
disposable.dispose(); disposable.dispose();
} }
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
} }

View File

@ -7,6 +7,9 @@ import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import android.preference.PreferenceFragment; import android.preference.PreferenceFragment;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.R;
@ -22,7 +25,6 @@ public class SharingFragment extends PreferenceFragment {
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_sharing); addPreferencesFromResource(R.xml.pref_sharing);
Preference manualStatus = findPreference("key_manual_status"); Preference manualStatus = findPreference("key_manual_status");
manualStatus.setOnPreferenceChangeListener((preference, newValue) -> { manualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
ListPreference lp = (ListPreference) findPreference("key_status_value"); ListPreference lp = (ListPreference) findPreference("key_status_value");
@ -44,6 +46,13 @@ public class SharingFragment extends PreferenceFragment {
}); });
} }
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState);
view.setBackgroundColor(getResources().getColor(android.R.color.white));
return view;
}
protected void updateListPreference(ListPreference lp,Object newValue,String storageKey){ protected void updateListPreference(ListPreference lp,Object newValue,String storageKey){
CharSequence [] entries = lp.getEntries(); CharSequence [] entries = lp.getEntries();