增加单独的fragment页面
This commit is contained in:
@@ -5,7 +5,6 @@ import android.util.Log;
|
|||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.lifecycle.Observer;
|
import androidx.lifecycle.Observer;
|
||||||
import androidx.loader.app.LoaderManager;
|
|
||||||
|
|
||||||
import com.tencent.mmkv.MMKV;
|
import com.tencent.mmkv.MMKV;
|
||||||
import com.ttstd.dialer.R;
|
import com.ttstd.dialer.R;
|
||||||
@@ -16,8 +15,8 @@ import com.ttstd.dialer.db.app.AppInfo;
|
|||||||
import com.ttstd.dialer.fragment.app.AppFragment;
|
import com.ttstd.dialer.fragment.app.AppFragment;
|
||||||
import com.ttstd.dialer.fragment.contact.ContactFragment;
|
import com.ttstd.dialer.fragment.contact.ContactFragment;
|
||||||
import com.ttstd.dialer.fragment.home.HomeFragment;
|
import com.ttstd.dialer.fragment.home.HomeFragment;
|
||||||
|
import com.ttstd.dialer.fragment.settings.SettingsFragment;
|
||||||
import com.ttstd.dialer.view.ApkPagerAdapter;
|
import com.ttstd.dialer.view.ApkPagerAdapter;
|
||||||
import com.ttstd.dialer.view.BaseFragmentPagerAdapter;
|
|
||||||
import com.ttstd.dialer.view.ScaleCircleNavigator;
|
import com.ttstd.dialer.view.ScaleCircleNavigator;
|
||||||
|
|
||||||
import net.lucode.hackware.magicindicator.ViewPagerHelper;
|
import net.lucode.hackware.magicindicator.ViewPagerHelper;
|
||||||
@@ -34,8 +33,9 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
|||||||
private ApkPagerAdapter mApkPagerAdapter;
|
private ApkPagerAdapter mApkPagerAdapter;
|
||||||
|
|
||||||
private List<Fragment> mFragments = new ArrayList<>();
|
private List<Fragment> mFragments = new ArrayList<>();
|
||||||
private HomeFragment mHomeFragment;
|
private SettingsFragment mSettingsFragment;
|
||||||
private ContactFragment mContactFragment;
|
private ContactFragment mContactFragment;
|
||||||
|
private HomeFragment mHomeFragment;
|
||||||
|
|
||||||
private int mCurrentIndex = 0;
|
private int mCurrentIndex = 0;
|
||||||
private int mFragmentSize = 0;
|
private int mFragmentSize = 0;
|
||||||
@@ -77,6 +77,13 @@ public class MainActivity extends BaseMvvmActivity<MainViewModel, ActivityMainBi
|
|||||||
|
|
||||||
mScaleCircleNavigator = new ScaleCircleNavigator(this);
|
mScaleCircleNavigator = new ScaleCircleNavigator(this);
|
||||||
|
|
||||||
|
if (mSettingsFragment == null) {
|
||||||
|
mSettingsFragment = new SettingsFragment();
|
||||||
|
mFragments.add(mContactFragment);
|
||||||
|
mFragmentSize += 1;
|
||||||
|
mCurrentIndex += 1;
|
||||||
|
}
|
||||||
|
|
||||||
boolean contactHome = mMMKV.decodeBool(CommonConfig.CONTACT_HOME_PAGE, false);
|
boolean contactHome = mMMKV.decodeBool(CommonConfig.CONTACT_HOME_PAGE, false);
|
||||||
if (!contactHome) {
|
if (!contactHome) {
|
||||||
mCurrentIndex += 1;
|
mCurrentIndex += 1;
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import androidx.fragment.app.Fragment;
|
|||||||
|
|
||||||
import com.hjq.toast.Toaster;
|
import com.hjq.toast.Toaster;
|
||||||
import com.ttstd.dialer.R;
|
import com.ttstd.dialer.R;
|
||||||
import com.ttstd.dialer.activity.app.AppListActivity;
|
|
||||||
import com.ttstd.dialer.activity.contact.list.ContactListActivity;
|
import com.ttstd.dialer.activity.contact.list.ContactListActivity;
|
||||||
import com.ttstd.dialer.base.mvvm.fragment.BaseMvvmFragment;
|
import com.ttstd.dialer.base.mvvm.fragment.BaseMvvmFragment;
|
||||||
import com.ttstd.dialer.databinding.FragmentHomeBinding;
|
import com.ttstd.dialer.databinding.FragmentHomeBinding;
|
||||||
@@ -231,9 +230,6 @@ public class HomeFragment extends BaseMvvmFragment<HomeViewModel, FragmentHomeBi
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void openAppList(View view) {
|
|
||||||
startActivity(new Intent(mContext, AppListActivity.class));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,63 @@
|
|||||||
|
package com.ttstd.dialer.fragment.settings;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.provider.Settings;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import com.ttstd.dialer.R;
|
||||||
|
import com.ttstd.dialer.activity.app.AppListActivity;
|
||||||
|
import com.ttstd.dialer.base.mvvm.fragment.BaseMvvmFragment;
|
||||||
|
import com.ttstd.dialer.databinding.FragmentSettingsBinding;
|
||||||
|
|
||||||
|
public class SettingsFragment extends BaseMvvmFragment<SettingsViewModel, FragmentSettingsBinding> {
|
||||||
|
private static final String TAG = "SettingsFragment";
|
||||||
|
|
||||||
|
private Activity mContext;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getLayoutId() {
|
||||||
|
return R.layout.fragment_settings;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initDataBinding() {
|
||||||
|
mContext = getActivity();
|
||||||
|
mViewModel.setContext(mContext);
|
||||||
|
mViewModel.setVDBinding(mViewDataBinding);
|
||||||
|
mViewModel.setLifecycle(getLifecycleSubject());
|
||||||
|
mViewDataBinding.setClick(new BtnClick());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initView(Bundle bundle) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void initData(Bundle savedInstanceState) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void fetchData() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public class BtnClick {
|
||||||
|
public void openSettings(View view) {
|
||||||
|
Intent intent = new Intent(Settings.ACTION_SETTINGS);
|
||||||
|
try {
|
||||||
|
startActivity(intent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(TAG, "openSettings: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void openAppList(View view) {
|
||||||
|
startActivity(new Intent(mContext, AppListActivity.class));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.ttstd.dialer.fragment.settings;
|
||||||
|
|
||||||
|
import com.trello.rxlifecycle4.android.FragmentEvent;
|
||||||
|
import com.ttstd.dialer.base.mvvm.BaseViewModel;
|
||||||
|
import com.ttstd.dialer.databinding.FragmentSettingsBinding;
|
||||||
|
|
||||||
|
public class SettingsViewModel extends BaseViewModel<FragmentSettingsBinding, FragmentEvent> {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -251,101 +251,6 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="0dp"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
|
||||||
|
|
||||||
<com.shehuan.niv.NiceImageView
|
|
||||||
android:id="@+id/niceImageView5"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="100dp"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:scaleType="centerCrop"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:textSize="@dimen/home_item_text_size"
|
|
||||||
android:textStyle="bold"
|
|
||||||
app:layout_constraintEnd_toEndOf="@+id/niceImageView5"
|
|
||||||
app:layout_constraintStart_toStartOf="@+id/niceImageView5"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/niceImageView5" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:onClick="@{click::openAppList}"
|
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:layout_constraintBottom_toBottomOf="parent"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent">
|
|
||||||
|
|
||||||
<com.shehuan.niv.NiceImageView
|
|
||||||
android:id="@+id/niceImageView6"
|
|
||||||
android:layout_width="100dp"
|
|
||||||
android:layout_height="100dp"
|
|
||||||
android:adjustViewBounds="true"
|
|
||||||
android:scaleType="centerCrop"
|
|
||||||
android:src="@drawable/ic_app"
|
|
||||||
android:textStyle="bold"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:maxLines="1"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:text="应用"
|
|
||||||
android:textColor="@color/black"
|
|
||||||
android:textSize="@dimen/home_item_text_size"
|
|
||||||
android:textStyle="bold"
|
|
||||||
app:layout_constraintEnd_toEndOf="@+id/niceImageView6"
|
|
||||||
app:layout_constraintStart_toStartOf="@+id/niceImageView6"
|
|
||||||
app:layout_constraintTop_toBottomOf="@+id/niceImageView6" />
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
143
app/src/main/res/layout/fragment_settings.xml
Normal file
143
app/src/main/res/layout/fragment_settings.xml
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<layout 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"
|
||||||
|
tools:context=".fragment.settings.SettingsFragment">
|
||||||
|
|
||||||
|
<data>
|
||||||
|
|
||||||
|
<variable
|
||||||
|
name="click"
|
||||||
|
type="com.ttstd.dialer.fragment.settings.SettingsFragment.BtnClick" />
|
||||||
|
</data>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="2"
|
||||||
|
android:orientation="horizontal" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="4"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:onClick="@{click::openSettings}"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<com.shehuan.niv.NiceImageView
|
||||||
|
android:id="@+id/niceImageView2"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:src="@drawable/ic_settings"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="设置"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="@dimen/home_item_text_size"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintEnd_toEndOf="@+id/niceImageView2"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/niceImageView2"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/niceImageView2" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:onClick="@{click::openAppList}"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent">
|
||||||
|
|
||||||
|
<com.shehuan.niv.NiceImageView
|
||||||
|
android:id="@+id/niceImageView6"
|
||||||
|
android:layout_width="100dp"
|
||||||
|
android:layout_height="100dp"
|
||||||
|
android:adjustViewBounds="true"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
|
android:src="@drawable/ic_app"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:text="应用"
|
||||||
|
android:textColor="@color/black"
|
||||||
|
android:textSize="@dimen/home_item_text_size"
|
||||||
|
android:textStyle="bold"
|
||||||
|
app:layout_constraintEnd_toEndOf="@+id/niceImageView6"
|
||||||
|
app:layout_constraintStart_toStartOf="@+id/niceImageView6"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/niceImageView6" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
</layout>
|
||||||
Reference in New Issue
Block a user