parent
d8ef883db9
commit
a12c42c55c
@ -0,0 +1,39 @@ |
||||
package com.community.pocket.ui.main; |
||||
|
||||
import android.os.Bundle; |
||||
import android.view.LayoutInflater; |
||||
import android.view.View; |
||||
import android.view.ViewGroup; |
||||
import android.widget.TextView; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
import androidx.annotation.Nullable; |
||||
import androidx.lifecycle.MutableLiveData; |
||||
import androidx.lifecycle.Observer; |
||||
|
||||
import com.community.pocket.ui.BaseFragment; |
||||
|
||||
import org.jetbrains.annotations.NotNull; |
||||
|
||||
public abstract class MainFragment extends BaseFragment { |
||||
|
||||
@NotNull |
||||
@Override |
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { |
||||
|
||||
View root = super.onCreateView(inflater, container, savedInstanceState); |
||||
final TextView textView = root.findViewById(viewId()); |
||||
MutableLiveData<String> mText = new MutableLiveData<>(); |
||||
mText.setValue(this.getClass().getName()); |
||||
mText.observe(getViewLifecycleOwner(), new Observer<String>() { |
||||
@Override |
||||
public void onChanged(@Nullable String s) { |
||||
textView.setText(s); |
||||
} |
||||
}); |
||||
|
||||
return root; |
||||
} |
||||
|
||||
protected abstract int viewId(); |
||||
} |
@ -0,0 +1,32 @@ |
||||
package com.community.pocket.ui.main; |
||||
|
||||
import android.os.Bundle; |
||||
|
||||
import androidx.navigation.NavController; |
||||
import androidx.navigation.Navigation; |
||||
import androidx.navigation.ui.NavigationUI; |
||||
|
||||
import com.community.pocket.R; |
||||
import com.community.pocket.ui.BaseActivity; |
||||
import com.google.android.material.bottomnavigation.BottomNavigationView; |
||||
|
||||
import org.xutils.view.annotation.ContentView; |
||||
import org.xutils.view.annotation.ViewInject; |
||||
|
||||
@ContentView((R.layout.activity_main_menu)) |
||||
public class MainMenu extends BaseActivity { |
||||
|
||||
@ViewInject(R.id.nav_view) |
||||
private BottomNavigationView navView; |
||||
|
||||
|
||||
@Override |
||||
protected void onCreate(Bundle savedInstanceState) { |
||||
super.onCreate(savedInstanceState); |
||||
|
||||
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment); |
||||
NavigationUI.setupWithNavController(navView, navController); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.community.pocket.ui.main.ui.dashboard; |
||||
|
||||
import com.community.pocket.R; |
||||
import com.community.pocket.ui.main.MainFragment; |
||||
|
||||
import org.xutils.view.annotation.ContentView; |
||||
|
||||
|
||||
@ContentView(R.layout.fragment_dashboard) |
||||
public class DashboardFragment extends MainFragment { |
||||
@Override |
||||
protected int viewId() { |
||||
return R.id.text_dashboard; |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
package com.community.pocket.ui.main.ui.dashboard; |
||||
|
||||
import androidx.lifecycle.LiveData; |
||||
import androidx.lifecycle.MutableLiveData; |
||||
import androidx.lifecycle.ViewModel; |
||||
|
||||
public class DashboardViewModel extends ViewModel { |
||||
|
||||
private MutableLiveData<String> mText; |
||||
|
||||
public DashboardViewModel() { |
||||
mText = new MutableLiveData<>(); |
||||
mText.setValue("This is dashboard fragment"); |
||||
} |
||||
|
||||
LiveData<String> getText() { |
||||
return mText; |
||||
} |
||||
} |
@ -0,0 +1,15 @@ |
||||
package com.community.pocket.ui.main.ui.home; |
||||
|
||||
import com.community.pocket.R; |
||||
import com.community.pocket.ui.main.MainFragment; |
||||
|
||||
import org.xutils.view.annotation.ContentView; |
||||
|
||||
@ContentView(R.layout.fragment_home) |
||||
public class HomeFragment extends MainFragment { |
||||
|
||||
@Override |
||||
protected int viewId() { |
||||
return R.id.text_home; |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
package com.community.pocket.ui.main.ui.home; |
||||
|
||||
import androidx.lifecycle.LiveData; |
||||
import androidx.lifecycle.MutableLiveData; |
||||
import androidx.lifecycle.ViewModel; |
||||
|
||||
public class HomeViewModel extends ViewModel { |
||||
|
||||
private MutableLiveData<String> mText; |
||||
|
||||
public HomeViewModel() { |
||||
mText = new MutableLiveData<>(); |
||||
mText.setValue("This is home fragment"); |
||||
} |
||||
|
||||
LiveData<String> getText() { |
||||
return mText; |
||||
} |
||||
} |
@ -0,0 +1,17 @@ |
||||
package com.community.pocket.ui.main.ui.info; |
||||
|
||||
import com.community.pocket.R; |
||||
import com.community.pocket.ui.main.MainFragment; |
||||
|
||||
import org.xutils.view.annotation.ContentView; |
||||
|
||||
@ContentView(R.layout.info_fragment) |
||||
public class InfoFragment extends MainFragment { |
||||
|
||||
@Override |
||||
protected int viewId() { |
||||
return R.id.text_info; |
||||
} |
||||
|
||||
|
||||
} |
@ -0,0 +1,19 @@ |
||||
package com.community.pocket.ui.main.ui.info; |
||||
|
||||
import androidx.lifecycle.LiveData; |
||||
import androidx.lifecycle.MutableLiveData; |
||||
import androidx.lifecycle.ViewModel; |
||||
|
||||
class InfoViewModel extends ViewModel { |
||||
|
||||
private MutableLiveData<String> mText; |
||||
|
||||
public InfoViewModel() { |
||||
mText = new MutableLiveData<>(); |
||||
mText.setValue("This is info fragment"); |
||||
} |
||||
|
||||
LiveData<String> getText() { |
||||
return mText; |
||||
} |
||||
} |
@ -0,0 +1,16 @@ |
||||
package com.community.pocket.ui.main.ui.notifications; |
||||
|
||||
import com.community.pocket.R; |
||||
import com.community.pocket.ui.main.MainFragment; |
||||
|
||||
import org.xutils.view.annotation.ContentView; |
||||
|
||||
|
||||
@ContentView(R.layout.fragment_notifications) |
||||
public class NotificationsFragment extends MainFragment { |
||||
|
||||
@Override |
||||
protected int viewId() { |
||||
return R.id.text_notifications; |
||||
} |
||||
} |
@ -0,0 +1,19 @@ |
||||
package com.community.pocket.ui.main.ui.notifications; |
||||
|
||||
import androidx.lifecycle.LiveData; |
||||
import androidx.lifecycle.MutableLiveData; |
||||
import androidx.lifecycle.ViewModel; |
||||
|
||||
public class NotificationsViewModel extends ViewModel { |
||||
|
||||
private MutableLiveData<String> mText; |
||||
|
||||
public NotificationsViewModel() { |
||||
mText = new MutableLiveData<>(); |
||||
mText.setValue("This is notifications fragment"); |
||||
} |
||||
|
||||
LiveData<String> getText() { |
||||
return mText; |
||||
} |
||||
} |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:viewportWidth="24.0" |
||||
android:viewportHeight="24.0"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M3,13h8L11,3L3,3v10zM3,21h8v-6L3,15v6zM13,21h8L21,11h-8v10zM13,3v6h8L21,3h-8z" /> |
||||
</vector> |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:viewportWidth="24.0" |
||||
android:viewportHeight="24.0"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M10,20v-6h4v6h5v-8h3L12,3 2,12h3v8z" /> |
||||
</vector> |
@ -0,0 +1,9 @@ |
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:width="24dp" |
||||
android:height="24dp" |
||||
android:viewportWidth="24.0" |
||||
android:viewportHeight="24.0"> |
||||
<path |
||||
android:fillColor="#FF000000" |
||||
android:pathData="M12,22c1.1,0 2,-0.9 2,-2h-4c0,1.1 0.89,2 2,2zM18,16v-5c0,-3.07 -1.64,-5.64 -4.5,-6.32L13.5,4c0,-0.83 -0.67,-1.5 -1.5,-1.5s-1.5,0.67 -1.5,1.5v0.68C7.63,5.36 6,7.92 6,11v5l-2,2v1h16v-1l-2,-2z" /> |
||||
</vector> |
@ -0,0 +1,36 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout 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" |
||||
android:id="@+id/container" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
android:paddingTop="?attr/actionBarSize"> |
||||
|
||||
<include layout="@layout/titlebar_layout" /> |
||||
|
||||
<com.google.android.material.bottomnavigation.BottomNavigationView |
||||
android:id="@+id/nav_view" |
||||
android:layout_width="0dp" |
||||
android:layout_height="wrap_content" |
||||
android:background="?android:attr/windowBackground" |
||||
app:labelVisibilityMode="labeled" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintLeft_toLeftOf="parent" |
||||
app:layout_constraintRight_toRightOf="parent" |
||||
app:menu="@menu/bottom_nav_menu" /> |
||||
|
||||
<fragment |
||||
android:id="@+id/nav_host_fragment" |
||||
android:name="androidx.navigation.fragment.NavHostFragment" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
app:defaultNavHost="true" |
||||
app:layout_constraintBottom_toTopOf="@id/nav_view" |
||||
app:layout_constraintLeft_toLeftOf="parent" |
||||
app:layout_constraintRight_toRightOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:navGraph="@navigation/mobile_navigation" |
||||
tools:ignore="FragmentTagUsage" /> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
@ -0,0 +1,22 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout 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" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context=".ui.main.ui.dashboard.DashboardFragment"> |
||||
|
||||
<TextView |
||||
android:id="@+id/text_dashboard" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginTop="8dp" |
||||
android:layout_marginEnd="8dp" |
||||
android:textAlignment="center" |
||||
android:textSize="20sp" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" /> |
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
@ -0,0 +1,22 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout 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" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context=".ui.main.ui.home.HomeFragment"> |
||||
|
||||
<TextView |
||||
android:id="@+id/text_home" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginTop="8dp" |
||||
android:layout_marginEnd="8dp" |
||||
android:textAlignment="center" |
||||
android:textSize="20sp" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" /> |
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
@ -0,0 +1,22 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout 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" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context=".ui.main.ui.notifications.NotificationsFragment"> |
||||
|
||||
<TextView |
||||
android:id="@+id/text_notifications" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="wrap_content" |
||||
android:layout_marginStart="8dp" |
||||
android:layout_marginTop="8dp" |
||||
android:layout_marginEnd="8dp" |
||||
android:textAlignment="center" |
||||
android:textSize="20sp" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" /> |
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
@ -0,0 +1,20 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout 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" |
||||
android:id="@+id/info" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="match_parent" |
||||
tools:context=".ui.main.ui.info.InfoFragment"> |
||||
|
||||
<TextView |
||||
android:id="@+id/text_info" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
android:text="@string/title_info" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintEnd_toEndOf="parent" |
||||
app:layout_constraintStart_toStartOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" /> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
@ -0,0 +1,19 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"> |
||||
|
||||
<item |
||||
android:id="@+id/navigation_home" |
||||
android:title="@string/title_home" /> |
||||
|
||||
<item |
||||
android:id="@+id/navigation_dashboard" |
||||
android:title="@string/title_dashboard" /> |
||||
|
||||
<item |
||||
android:id="@+id/navigation_notifications" |
||||
android:title="@string/title_notifications" /> |
||||
<item |
||||
android:id="@+id/navigation_info" |
||||
android:title="@string/title_info" /> |
||||
|
||||
</menu> |
@ -0,0 +1,29 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<navigation 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" |
||||
android:id="@+id/mobile_navigation" |
||||
app:startDestination="@+id/navigation_home"> |
||||
|
||||
<fragment |
||||
android:id="@+id/navigation_home" |
||||
android:name="com.community.pocket.ui.main.ui.home.HomeFragment" |
||||
android:label="@string/title_home" |
||||
tools:layout="@layout/fragment_home" /> |
||||
|
||||
<fragment |
||||
android:id="@+id/navigation_dashboard" |
||||
android:name="com.community.pocket.ui.main.ui.dashboard.DashboardFragment" |
||||
android:label="@string/title_dashboard" |
||||
tools:layout="@layout/fragment_dashboard" /> |
||||
|
||||
<fragment |
||||
android:id="@+id/navigation_notifications" |
||||
android:name="com.community.pocket.ui.main.ui.notifications.NotificationsFragment" |
||||
android:label="@string/title_notifications" |
||||
tools:layout="@layout/fragment_notifications" /> |
||||
<fragment |
||||
android:id="@+id/navigation_info" |
||||
android:name="com.community.pocket.ui.main.ui.info.InfoFragment" |
||||
android:label="@string/title_info" /> |
||||
</navigation> |
Loading…
Reference in new issue