bottom navi with frags and activities

This commit is contained in:
Adam Domagalski 2018-10-25 00:19:12 +02:00
parent d60a3c413c
commit 5dab4eaf4b
8 changed files with 72 additions and 55 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 (1)" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" 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

@ -1,5 +1,7 @@
package com.uam.wmi.findmytutor.activity; package com.uam.wmi.findmytutor.activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent; import android.content.Intent;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -39,6 +41,7 @@ public abstract class BaseActivity
private ListView listView; private ListView listView;
private ArrayList<String> stringArrayList; private ArrayList<String> stringArrayList;
private ListViewAdapter adapter; private ListViewAdapter adapter;
private SharingFragment sharingFragment;
@Override @Override
@ -48,6 +51,8 @@ public abstract class BaseActivity
navigationView = findViewById(R.id.navigation); navigationView = findViewById(R.id.navigation);
navigationView.setOnNavigationItemSelectedListener(this); navigationView.setOnNavigationItemSelectedListener(this);
sharingFragment = new SharingFragment();
} }
@ -161,36 +166,37 @@ public abstract class BaseActivity
overridePendingTransition(0,0); overridePendingTransition(0,0);
} }
private void setFragment(Fragment fragment) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.activity_content, fragment);
fragmentTransaction.commit();
}
private void removeFragment(Fragment fragment) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.remove(fragment);
fragmentTransaction.commit();
}
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
navigationView.postDelayed(() -> { navigationView.postDelayed(() -> {
int itemId = item.getItemId(); int itemId = item.getItemId();
if (itemId == R.id.nav_map) { if (itemId == R.id.nav_map) {
startActivity(new Intent(this, MapActivity.class)); removeFragment(sharingFragment);
// startActivity(new Intent(this, MapActivity.class));
} else if (itemId == R.id.nav_profile) { } else if (itemId == R.id.nav_profile) {
startActivity(new Intent(this, ProfileActivity.class)); // startActivity(new Intent(this, ProfileActivity.class));
setFragment(sharingFragment);
} else if (itemId == R.id.nav_notif) { } else if (itemId == R.id.nav_notif) {
startActivity(new Intent(this, NotificationsActivity.class)); startActivity(new Intent(this, NotificationsActivity.class));
} }
finish(); //finish();
}, 300); }, 300);
return true;
// navigationView.postDelayed(() -> { return true;
// int itemId = item.getItemId();
// switch (itemId) {
// case R.id.nav_profile:
// startActivity(new Intent(this, ProfileActivity.class));
// case R.id.nav_map:
// startActivity(new Intent(this, MapActivity.class));
// case R.id.nav_notif:
// startActivity(new Intent(this, NotificationsActivity.class));
// }
//
// finish();
// }, 300);
// return true;
} }
private void updateNavigationBarState() { private void updateNavigationBarState() {

View File

@ -36,7 +36,7 @@ public class SharingActivity extends AppCompatPreferenceActivity {
@Override @Override
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.layout.pref_sharing);
Preference manualStatus = findPreference("key_manual_status"); Preference manualStatus = findPreference("key_manual_status");
manualStatus.setOnPreferenceChangeListener((preference, newValue) -> { manualStatus.setOnPreferenceChangeListener((preference, newValue) -> {

View File

@ -24,7 +24,7 @@ public class SharingFragment extends PreferenceFragment {
@Override @Override
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.layout.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");

View File

@ -15,7 +15,7 @@ public class StartupActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
if (PrefUtils.isLoggedIn(getApplicationContext())){ if (PrefUtils.isLoggedIn(getApplicationContext())){
Intent startupIntent = new Intent(this, MainActivity.class); Intent startupIntent = new Intent(this, MapActivity.class);
startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(startupIntent); startActivity(startupIntent);
finish(); finish();
@ -31,7 +31,7 @@ public class StartupActivity extends AppCompatActivity {
@Override @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) { protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == AUTHENTICATION_REQUEST_CODE && resultCode == Activity.RESULT_OK) { if (requestCode == AUTHENTICATION_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
Intent startupIntent = new Intent(this, MainActivity.class); Intent startupIntent = new Intent(this, MapActivity.class);
startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(startupIntent); startActivity(startupIntent);
} }

View File

@ -10,7 +10,7 @@
<com.mapbox.mapboxsdk.maps.MapView <com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView" android:id="@+id/mapView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:visibility="visible" android:visibility="visible"
mapbox:mapbox_cameraTargetLat="52.466799" mapbox:mapbox_cameraTargetLat="52.466799"
mapbox:mapbox_cameraTargetLng="16.927002" mapbox:mapbox_cameraTargetLng="16.927002"
@ -19,13 +19,4 @@
</com.mapbox.mapboxsdk.maps.MapView> </com.mapbox.mapboxsdk.maps.MapView>
<include
android:id="@+id/navigation"
layout="@layout/element_bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>

View File

@ -5,30 +5,45 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<android.support.design.widget.CoordinatorLayout
android:id="@+id/cl_root_coordinator"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
/> <android.support.design.widget.AppBarLayout
<FrameLayout android:id="@+id/app_bar_layout"
android:id="@+id/activity_content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?actionBarSize" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?actionBarSize">
<FrameLayout
android:id="@+id/activity_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/navigation"/>
<include
android:id="@id/navigation"
layout="@layout/element_bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
<!--<android.support.design.widget.NavigationView-->
<!--android:id="@+id/navigation"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_gravity="start"-->
<!--/>-->
<android.support.design.widget.NavigationView <android.support.design.widget.NavigationView
android:id="@+id/nav_view" android:id="@+id/nav_view"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -37,5 +52,6 @@
app:headerLayout="@layout/nav_header_main" app:headerLayout="@layout/nav_header_main"
app:menu="@menu/activity_main_drawer"> app:menu="@menu/activity_main_drawer">
</android.support.design.widget.NavigationView> </android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout> </android.support.v4.widget.DrawerLayout>

View File

@ -1,7 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:tools="http://schemas.android.com/tools" <PreferenceScreen xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
tools:ignore="MissingDefaultResource"> xmlns:app="http://schemas.android.com/apk/res-auto"
tools:ignore="MissingDefaultResource"
android:layout_width="match_parent"
android:layout_height="match_parent">
<PreferenceCategory android:title="@string/settings_category_location"> <PreferenceCategory android:title="@string/settings_category_location">
<SwitchPreference <SwitchPreference
android:defaultValue="false" android:defaultValue="false"
@ -56,6 +59,7 @@
android:title="@string/title_manual_location" android:title="@string/title_manual_location"
/> />
</PreferenceCategory>
</PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>