主菜单框架

0515
panqihua 5 years ago
parent d8ef883db9
commit a12c42c55c
  1. 3
      app/build.gradle
  2. 1
      app/src/main/AndroidManifest.xml
  3. 2
      app/src/main/java/com/community/pocket/ui/BaseFragment.java
  4. 4
      app/src/main/java/com/community/pocket/ui/login/LoginActivity.java
  5. 39
      app/src/main/java/com/community/pocket/ui/main/MainFragment.java
  6. 32
      app/src/main/java/com/community/pocket/ui/main/MainMenu.java
  7. 15
      app/src/main/java/com/community/pocket/ui/main/ui/dashboard/DashboardFragment.java
  8. 19
      app/src/main/java/com/community/pocket/ui/main/ui/dashboard/DashboardViewModel.java
  9. 15
      app/src/main/java/com/community/pocket/ui/main/ui/home/HomeFragment.java
  10. 19
      app/src/main/java/com/community/pocket/ui/main/ui/home/HomeViewModel.java
  11. 17
      app/src/main/java/com/community/pocket/ui/main/ui/info/InfoFragment.java
  12. 19
      app/src/main/java/com/community/pocket/ui/main/ui/info/InfoViewModel.java
  13. 16
      app/src/main/java/com/community/pocket/ui/main/ui/notifications/NotificationsFragment.java
  14. 19
      app/src/main/java/com/community/pocket/ui/main/ui/notifications/NotificationsViewModel.java
  15. 9
      app/src/main/res/drawable/ic_dashboard_black_24dp.xml
  16. 9
      app/src/main/res/drawable/ic_home_black_24dp.xml
  17. 9
      app/src/main/res/drawable/ic_notifications_black_24dp.xml
  18. 36
      app/src/main/res/layout/main/layout/activity_main_menu.xml
  19. 22
      app/src/main/res/layout/main/layout/fragment_dashboard.xml
  20. 22
      app/src/main/res/layout/main/layout/fragment_home.xml
  21. 22
      app/src/main/res/layout/main/layout/fragment_notifications.xml
  22. 20
      app/src/main/res/layout/main/layout/info_fragment.xml
  23. 19
      app/src/main/res/menu/bottom_nav_menu.xml
  24. 29
      app/src/main/res/navigation/mobile_navigation.xml
  25. 4
      app/src/main/res/values-en-rUS/strings.xml
  26. 4
      app/src/main/res/values-zh-rCN/strings.xml
  27. 4
      app/src/main/res/values/strings.xml

@ -23,7 +23,7 @@ android {
sourceSets {
main {
res {
srcDirs 'src/main/res', 'src/main/res/layout/resetpwd', 'src/main/res/layout/resetpwd/layout'
srcDirs 'src/main/res', 'src/main/res/layout/resetpwd', 'src/main/res/layout/resetpwd/layout', 'src/main/res/layout/main', 'src/main/res/layout/main/layout'
}
}
}
@ -40,6 +40,7 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.navigation:navigation-fragment:2.2.1'
implementation 'androidx.navigation:navigation-ui:2.2.1'
implementation 'androidx.vectordrawable:vectordrawable:1.1.0'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'

@ -10,6 +10,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<activity android:name=".ui.main.MainMenu" />
<activity android:name=".ui.resetpwd.ResetPwdActivity" />
<activity android:name=".ui.register.RegisterActivity" />
<activity android:name=".ui.login.LoginActivity">

@ -15,7 +15,7 @@ import org.xutils.x;
* 封装初始化xutils逻辑
*/
public abstract class BaseFragment extends Fragment {
@Nullable
@NonNull
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return x.view().inject(this, inflater, container);//fragment注解

@ -21,6 +21,7 @@ import androidx.lifecycle.ViewModelProvider;
import com.community.pocket.R;
import com.community.pocket.ui.BaseActivity;
import com.community.pocket.ui.main.MainMenu;
import com.community.pocket.ui.register.RegisterActivity;
import com.community.pocket.ui.resetpwd.ResetPwdActivity;
import com.community.pocket.util.PropertiesUtil;
@ -93,8 +94,9 @@ public class LoginActivity extends BaseActivity {
}
setResult(Activity.RESULT_OK);
startActivity(new Intent(getApplicationContext(), MainMenu.class));
//Complete and destroy login activity once successful
// finish();
finish();
}
});

@ -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>

@ -26,4 +26,8 @@
<string name="next">Next</string>
<string name="previous">Previous</string>
<string name="action_sendcode">send code</string>
<string name="title_home">Forum</string>
<string name="title_dashboard">Visitor</string>
<string name="title_notifications">Recycle</string>
<string name="title_info">MyInformation</string>
</resources>

@ -26,4 +26,8 @@
<string name="next">下一步</string>
<string name="previous">上一步</string>
<string name="action_sendcode">发送验证码</string>
<string name="title_home">论坛</string>
<string name="title_dashboard">访客管理</string>
<string name="title_notifications">垃圾上门回收</string>
<string name="title_info">我的信息</string>
</resources>

@ -27,6 +27,10 @@
<string name="next">Next</string>
<string name="previous">Previous</string>
<string name="action_sendcode">send code</string>
<string name="title_home">Forum</string>
<string name="title_dashboard">Visitor</string>
<string name="title_notifications">Recycle</string>
<string name="title_info">MyInformation</string>
<!-- Strings used for fragments for navigation -->
<!-- Strings used for fragments for navigation -->

Loading…
Cancel
Save