Skip to content

Commit

Permalink
Android Change/BindPhoneNum Impl
Browse files Browse the repository at this point in the history
  • Loading branch information
AigioL committed Mar 4, 2022
1 parent 6c905ab commit 33b76c6
Show file tree
Hide file tree
Showing 18 changed files with 700 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public interface ITelephonyService
if ((!string.IsNullOrWhiteSpace(value)) &&
(string.IsNullOrWhiteSpace(textBoxText) ||
(textBoxText.Length < value.Length &&
value.Substring(0, textBoxText.Length) == textBoxText)))
value[..textBoxText.Length] == textBoxText)))
{
return value;
}
Expand Down
54 changes: 29 additions & 25 deletions src/ST.Client.Android/GoToPlatformPages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,34 +84,38 @@ static void StartActivity(this Activity activity, Type activityType, byte[] view
return default;
}

public static void StartActivity(Activity activity, Type activityType, object viewModel, Type? viewModelType = null)
{
viewModelType ??= viewModel.GetType();
var viewModel_ = Serializable.SMP(viewModelType, viewModel);
#if DEBUG
var t = Serializable.DMP(viewModelType, viewModel_);
#endif
StartActivity(activity, activityType, viewModel_);
}
// [Obsolete]
// public static void StartActivity(Activity activity, Type activityType, object viewModel, Type? viewModelType = null)
// {
// viewModelType ??= viewModel.GetType();
// var viewModel_ = Serializable.SMP(viewModelType, viewModel);
//#if DEBUG
// var t = Serializable.DMP(viewModelType, viewModel_);
//#endif
// StartActivity(activity, activityType, viewModel_);
// }

public static void StartActivity(Fragment fragment, Type activityType, object viewModel, Type? viewModelType = null)
{
var activity = fragment.Activity;
if (activity == null) return;
StartActivity(activity, activityType, viewModel, viewModelType);
}
// [Obsolete]
// public static void StartActivity(Fragment fragment, Type activityType, object viewModel, Type? viewModelType = null)
// {
// var activity = fragment.Activity;
// if (activity == null) return;
// StartActivity(activity, activityType, viewModel, viewModelType);
// }

public static void StartActivity<TActivity>(Activity activity, object viewModel, Type? viewModelType = null)
{
StartActivity(activity, typeof(TActivity), viewModel, viewModelType);
}
// [Obsolete]
// public static void StartActivity<TActivity>(Activity activity, object viewModel, Type? viewModelType = null)
// {
// StartActivity(activity, typeof(TActivity), viewModel, viewModelType);
// }

public static void StartActivity<TActivity>(Fragment fragment, object viewModel, Type? viewModelType = null)
{
var activity = fragment.Activity;
if (activity == null) return;
StartActivity<TActivity>(activity, viewModel, viewModelType);
}
// [Obsolete]
// public static void StartActivity<TActivity>(Fragment fragment, object viewModel, Type? viewModelType = null)
// {
// var activity = fragment.Activity;
// if (activity == null) return;
// StartActivity<TActivity>(activity, viewModel, viewModelType);
// }

public static void StartActivity<TViewModel>(Activity activity, Type activityType, TViewModel viewModel)
{
Expand Down
12 changes: 12 additions & 0 deletions src/ST.Client.Android/ST.Client.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,18 @@
<AndroidBoundLayout Include="..\ST.Client.Mobile.Droid.Design\ui\src\main\res\layout\fragment_basic_profile_content.xml">
<Link>Resources\layout\fragment_basic_profile_content.xml</Link>
</AndroidBoundLayout>
<AndroidBoundLayout Include="..\ST.Client.Mobile.Droid.Design\ui\src\main\res\layout\fragment_bind_phone_number.xml">
<Link>Resources\layout\fragment_bind_phone_number.xml</Link>
</AndroidBoundLayout>
<AndroidBoundLayout Include="..\ST.Client.Mobile.Droid.Design\ui\src\main\res\layout\fragment_bind_phone_number_content.xml">
<Link>Resources\layout\fragment_bind_phone_number_content.xml</Link>
</AndroidBoundLayout>
<AndroidBoundLayout Include="..\ST.Client.Mobile.Droid.Design\ui\src\main\res\layout\fragment_change_bind_phone_number.xml">
<Link>Resources\layout\fragment_change_bind_phone_number.xml</Link>
</AndroidBoundLayout>
<AndroidBoundLayout Include="..\ST.Client.Mobile.Droid.Design\ui\src\main\res\layout\fragment_change_bind_phone_number_content.xml">
<Link>Resources\layout\fragment_change_bind_phone_number_content.xml</Link>
</AndroidBoundLayout>
<AndroidBoundLayout Include="..\ST.Client.Mobile.Droid.Design\ui\src\main\res\layout\fragment_community_fix.xml">
<Link>Resources\layout\fragment_community_fix.xml</Link>
</AndroidBoundLayout>
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Application.UI.Resx;
using System.Application.UI.ViewModels;
using Fragment = AndroidX.Fragment.App.Fragment;
using NUserService = System.Application.Services.UserService;
using static System.Application.UI.ViewModels.UserProfileWindowViewModel;

namespace System.Application.UI.Activities
{
Expand All @@ -33,21 +35,26 @@ protected override void OnCreate2(Bundle? savedInstanceState)

var adapter = new ViewPagerWithTabLayoutAdapter(this, this);
binding!.pager.SetupWithTabLayout(binding!.tab_layout, adapter);

var position = this.GetViewModel<SubPageType>();
GoToSubPage(position);
}

int ViewPagerAdapter.IHost.ItemCount => 2;
int ViewPagerAdapter.IHost.ItemCount => pageCount;

Fragment ViewPagerAdapter.IHost.CreateFragment(int position) => position switch
{
0 => new UserBasicInfoFragment(),
1 => new UserAccountBindFragment(),
2 => NUserService.Current.HasPhoneNumber ? new ChangePhoneNumberFragment() : new BindPhoneNumberFragment(),
_ => throw new ArgumentOutOfRangeException(nameof(position), position.ToString()),
};

string ViewPagerWithTabLayoutAdapter.IHost.GetPageTitle(int position) => position switch
{
0 => AppResources.User_BasicInfo,
1 => AppResources.User_AccountBind,
2 => NUserService.Current.HasPhoneNumber ? AppResources.User_ChangePhoneNum : AppResources.User_BindPhoneNum,
_ => throw new ArgumentOutOfRangeException(nameof(position), position.ToString()),
};

Expand All @@ -64,5 +71,26 @@ public override void OnBackPressed()

base.OnBackPressed();
}

const int pageCount = 3;
public static void StartActivity(Activity activity, SubPageType position = 0)
{
if (position.IsDefined())
{
GoToPlatformPages.StartActivity<UserProfileActivity, SubPageType>(activity, position);
}
else
{
activity.StartActivity<UserProfileActivity>();
}
}

public void GoToSubPage(SubPageType position)
{
if (position.IsDefined())
{
binding!.pager.SetCurrentItem((int)position, false);
}
}
}
}
59 changes: 33 additions & 26 deletions src/ST.Client.Android/UI/Fragments/MyFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,19 @@ public override void OnCreateView(View view)
return;
}
#if !DEBUG
var isUnderConstruction = e.Current.Id switch
{
PreferenceButton.BindPhoneNumber or
PreferenceButton.ChangePhoneNumber or PreferenceButton.UserProfile => true,
_ => false,
};
if (isUnderConstruction)
{
MainApplication.ShowUnderConstructionTips();
return;
}
#endif
//#if !DEBUG
// var isUnderConstruction = e.Current.Id switch
// {
// PreferenceButton.BindPhoneNumber or
// PreferenceButton.ChangePhoneNumber or PreferenceButton.UserProfile => true,
// _ => false,
// };
// if (isUnderConstruction)
// {
// MainApplication.ShowUnderConstructionTips();
// return;
// }
//#endif
#if __XAMARIN_FORMS__
var route = e.Current.Id switch
Expand All @@ -73,16 +73,23 @@ PreferenceButton.BindPhoneNumber or
}
#endif
var activityType = e.Current.Id switch
switch (e.Current.Id)
{
PreferenceButton.UserProfile => typeof(UserProfileActivity),
PreferenceButton.BindPhoneNumber => typeof(BindPhoneNumberActivity),
PreferenceButton.ChangePhoneNumber => typeof(ChangePhoneNumberActivity),
PreferenceButton.Settings => typeof(SettingsActivity),
PreferenceButton.About => typeof(AboutActivity),
_ => (Type?)null,
};
if (activityType != null) this.StartActivity(activityType);
case PreferenceButton.UserProfile:
this.StartActivity<UserProfileActivity>();
break;
case PreferenceButton.BindPhoneNumber:
case PreferenceButton.ChangePhoneNumber:
UserProfileActivity.StartActivity(RequireActivity(),
UserProfileWindowViewModel.SubPageType.ChangeOrBindPhoneNumber);
break;
case PreferenceButton.Settings:
this.StartActivity<SettingsActivity>();
break;
case PreferenceButton.About:
this.StartActivity<AboutActivity>();
break;
}
};
binding.rvPreferenceButtons.SetLinearLayoutManager();
binding.rvPreferenceButtons.AddVerticalGroupItemDecoration(binding.rvPreferenceButtons.PaddingTop);
Expand All @@ -93,9 +100,9 @@ protected override bool OnClick(View view)
{
if (view.Id == Resource.Id.layoutUser)
{
#if !DEBUG
MainApplication.ShowUnderConstructionTips();
#else
//#if !DEBUG
// MainApplication.ShowUnderConstructionTips();
//#else
if (UserService.Current.IsAuthenticated)
{
this.StartActivity<UserProfileActivity>();
Expand All @@ -104,7 +111,7 @@ protected override bool OnClick(View view)
{
this.StartActivity<LoginOrRegisterActivity>();
}
#endif
//#endif
return true;
}
//else if (view.Id == Resource.Id.???)
Expand Down
Loading

0 comments on commit 33b76c6

Please sign in to comment.