public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.Inflate(Resource.Layout.preference_fragment, container, false); themeSwitcher = view.FindViewById <Switch>(Resource.Id.switcher); materialCard = view.FindViewById <MaterialCardView>(Resource.Id.donationCard); donationTextView = view.FindViewById <TextView>(Resource.Id.donationTextView); donationRefreshButton = view.FindViewById <Button>(Resource.Id.donationRefreshButton); aboutButton = view.FindViewById <Google.Android.Material.Button.MaterialButton>(Resource.Id.aboutButton); reportButton = view.FindViewById <Google.Android.Material.Button.MaterialButton>(Resource.Id.reportButton); donationRefreshButton.Click += DonationRefreshButton_Click; aboutButton.Click += AboutButton_Click; reportButton.Click += ReportButton_Click; themeSwitcher.SetOnCheckedChangeListener(this); sharedPreferences = PreferenceManager.GetDefaultSharedPreferences(this.Context); var stateIsChecked = sharedPreferences.GetBoolean("Saved_Switch", false); if (themeSwitcher != null) { themeSwitcher.Checked = stateIsChecked; if (stateIsChecked) { themeSwitcher.Text = "Toggle to turn off the lights"; } else { themeSwitcher.Text = "Toogle to turn the lights on"; } } var userHasDonated = ExtractRAdManager.UserHasDonated(this.Context); if (!userHasDonated) { materialCard.SetBackgroundColor(Android.Graphics.Color.DarkRed); donationTextView.SetTextColor(Android.Graphics.Color.GhostWhite); donationTextView.Text = Context.GetString(Resource.String.user_no_donation); donationRefreshButton.Visibility = ViewStates.Visible; } else { materialCard.SetBackgroundColor(Android.Graphics.Color.DarkGreen); donationTextView.SetTextColor(Android.Graphics.Color.GhostWhite); donationTextView.Text = Context.GetString(Resource.String.user_donated); donationRefreshButton.Visibility = ViewStates.Gone; } return(view); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); newTaskFragment = new NewTaskFragment(this); historyFragment = new HistoryFragment(this); donationFragment = new DonationFragment(); preferenceFragment = new PreferenceFragment(this); toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.mainToolBar); SetSupportActionBar(toolbar); navigation = FindViewById <Google.Android.Material.BottomNavigation.BottomNavigationView>(Resource.Id.navigation); navigation.SetOnNavigationItemSelectedListener(this); ChangeFragment(newTaskFragment); MobileAds.Initialize(this); if (!ExtractRAdManager.UserHasDonated(this)) { interstitialAd = ExtractRAdManager.LoadAdInBackground(this); } if (AppCompatDelegate.DefaultNightMode == AppCompatDelegate.ModeNightYes) { navigation.ItemIconTintList = Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.GhostWhite); navigation.ItemTextColor = Android.Content.Res.ColorStateList.ValueOf(Android.Graphics.Color.GhostWhite); } else if (AppCompatDelegate.DefaultNightMode == AppCompatDelegate.ModeNightNo) { string accentColorString = "#" + GetColor(Resource.Color.colorAccent).ToString("X"); Android.Graphics.Color accentColor = Android.Graphics.Color.ParseColor(accentColorString); navigation.ItemIconTintList = Android.Content.Res.ColorStateList.ValueOf(accentColor); navigation.ItemTextColor = Android.Content.Res.ColorStateList.ValueOf(accentColor); } }
public override async void OnActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 2500) { if (paystack != null) { //Verify the transaction. string storedReference = paystack.GetReference(); var result = await paystack.VerifyTransactionAsync(storedReference); if (result.status) { //Transaction was successful. //Save user donation. //var editor = sharedPreferences.Edit(); //editor.PutBoolean(ExtractRAdManager.USER_DONATION_KEY, true); //editor.Apply(); ////User has donated. /// ExtractRAdManager.SetUserHasDonated(this.Context); } if (null != result) { Toast.MakeText(Context, $"{result.message} {result.data.amount}", ToastLength.Long).Show(); } else { Toast.MakeText(Context, "Error occurred", ToastLength.Short).Show(); } } } base.OnActivityResult(requestCode, resultCode, data); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.export_activity); toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.exportToolbar); adView = FindViewById <AdView>(Resource.Id.adView); SetSupportActionBar(toolbar); SupportActionBar.SetDisplayHomeAsUpEnabled(true); SupportActionBar.SetDefaultDisplayHomeAsUpEnabled(true); double count = 0; var getExtra = Intent.Extras.Get("itemCount"); if (getExtra != null) { count = (double)getExtra; } SupportActionBar.Title = $"Export {count} Items"; SupportFragmentManager.BeginTransaction() .Add(Resource.Id.exportPlaceholder, new NewExportFragment(this)) .Commit(); //Present simple banner ads. AdRequest adRequest = new AdRequest.Builder().Build(); //Load ad if the user has not donated. if (!ExtractRAdManager.UserHasDonated(this)) { adView.LoadAd(adRequest); } }
private async void DonationRefreshButton_Click(object sender, EventArgs e) { await System.Threading.Tasks.Task.Run(() => { try { mainActivity.RunOnUiThread(() => { donationRefreshButton.Text = "Verifying...."; }); //Try to refresh the user's transaction. string file = System.IO.File.ReadAllText(System.IO.Path.Combine(PathHelper.GetOrCreateAuthDetailsPath(), "auth.exr")); string json = Encoding.UTF8.GetString(Convert.FromBase64String(file)); ProviderAuthorisationResult providerAuthorisationResult = JsonConvert.DeserializeObject <ProviderAuthorisationResult>(json); if (providerAuthorisationResult.Status.ToLower() == "ok") { mainActivity.RunOnUiThread(() => { GetDialogBuilder() .SetTitle("Transaction Successfully Verified") .SetMessage("Congratulations! We have successfully verified your transaction. " + "You should restart the application for the changes to take effect. " + "Sorry for the inconvenience.") .SetCancelable(false) .SetNeutralButton("OK", (s, e) => { return; }) .Show(); donationRefreshButton.Text = "I have Donated"; }); ExtractRAdManager.SetUserHasDonated(this.Context); } else { mainActivity.RunOnUiThread(() => { GetDialogBuilder() .SetTitle("Transaction Failed") .SetMessage("We are unable to verify your transaction. It looks like your transaction was not successful.") .SetCancelable(false) .SetNeutralButton("OK", (s, e) => { return; }) .Show(); donationRefreshButton.Text = "I have Donated"; }); } } catch { mainActivity.RunOnUiThread(() => { GetDialogBuilder() .SetTitle("An Error Occured") .SetMessage("We are unable to validate the transaction right now. Please try again later.") .SetCancelable(false) .SetNeutralButton("OK", (s, e) => { return; }) .Show(); donationRefreshButton.Text = "I have Donated"; }); } }); }