Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0531a28

Browse files
committed
remove ctfapp instance
1 parent19ae7f3 commit0531a28

File tree

13 files changed

+90
-139
lines changed

13 files changed

+90
-139
lines changed

‎CTF/src/main/AndroidManifest.xml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
<uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE" />
1313

1414
<application
15-
android:name=".CTFApp"
1615
android:allowBackup="true"
1716
android:icon="@mipmap/ic_launcher"
1817
android:label="@string/app_name"

‎CTF/src/main/java/ca/mcgill/science/ctf/CTFApp.java‎

Lines changed: 0 additions & 32 deletions
This file was deleted.

‎CTF/src/main/java/ca/mcgill/science/ctf/LoginActivity.java‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
importbutterknife.BindView;
2121
importbutterknife.ButterKnife;
22-
importca.allanwang.capsule.library.logging.CLog;
2322
importca.mcgill.science.ctf.api.ITEPID;
2423
importca.mcgill.science.ctf.api.Session;
2524
importca.mcgill.science.ctf.api.SessionRequest;
@@ -149,7 +148,7 @@ public void onResponse(Call<Session> call, Response<Session> response) {
149148
mPasswordField.requestFocus();
150149
}else {
151150
SessionresponseData =response.body();
152-
finalAccountaccount =newAccount(responseData.getUser().getShortUser(),AccountUtil.accountType);
151+
finalAccountaccount =newAccount(responseData.getUser().getShortUser(),AccountUtil.getAccountType(LoginActivity.this));
153152

154153
if (getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT,false)) {
155154
BundleuserData =newBundle();
@@ -159,7 +158,7 @@ public void onResponse(Call<Session> call, Response<Session> response) {
159158
}
160159

161160
// set the auth token using the session we received
162-
mAccountManager.setAuthToken(account,AccountUtil.tokenType,
161+
mAccountManager.setAuthToken(account,AccountUtil.getTokenType(LoginActivity.this),
163162
Base64.encodeToString((responseData.getUser().getShortUser() +":" +responseData.get_id()).getBytes(),Base64.CRLF));
164163
finish();
165164
}

‎CTF/src/main/java/ca/mcgill/science/ctf/MainActivity.java‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
importandroid.annotation.SuppressLint;
44
importandroid.content.Context;
5+
importandroid.content.Intent;
56
importandroid.content.SharedPreferences;
67
importandroid.graphics.Color;
78
importandroid.net.wifi.WifiInfo;
@@ -30,14 +31,15 @@
3031
importca.allanwang.capsule.library.item.DrawerItem;
3132
importca.allanwang.capsule.library.logging.CallbackLogTree;
3233
importca.mcgill.science.ctf.activities.SearchActivity;
34+
importca.mcgill.science.ctf.api.TEPIDAPI;
35+
importca.mcgill.science.ctf.auth.AccountUtil;
3336
importca.mcgill.science.ctf.fragments.AccountFragment;
3437
importca.mcgill.science.ctf.fragments.BaseFragment;
3538
importca.mcgill.science.ctf.fragments.DashboardFragment;
3639
importca.mcgill.science.ctf.fragments.PreTicketFragment;
3740
importca.mcgill.science.ctf.fragments.RoomsViewPagerFragment;
3841
importca.mcgill.science.ctf.fragments.SettingsFragment;
3942
importca.mcgill.science.ctf.utils.Preferences;
40-
importca.mcgill.science.ctf.utils.Utils;
4143
importio.fabric.sdk.android.Fabric;
4244
importtimber.log.Timber;
4345

@@ -62,6 +64,7 @@ protected void onCreate(final Bundle savedInstanceState) {
6264
}
6365
Preferences.setTheme(this);
6466
mToken =getIntent().getStringExtra(StartActivity.EXTRA_TOKEN);
67+
TEPIDAPI.Companion.setInstance(mToken,this);//to be sure, set api instance here
6568
super.onCreate(savedInstanceState);
6669
onVersionUpdate(BuildConfig.VERSION_CODE, () ->ChangelogDialog.show(MainActivity.this,R.xml.changelog));
6770
cFab.hide();//we don't use the fab for now
@@ -149,10 +152,6 @@ private boolean isWifiConnected() {
149152
returnfalse;
150153
}
151154

152-
privatebooleanisNetworkAvailable() {
153-
returnUtils.isNetworkAvailable(this);
154-
}
155-
156155
@Override
157156
publicbooleanonCreateOptionsMenu(Menumenu) {
158157
// Inflate the menu; this adds items to the action bar if it is present.
@@ -177,4 +176,13 @@ public boolean onOptionsItemSelected(MenuItem item) {
177176
returnsuper.onOptionsItemSelected(item);
178177
}
179178

179+
publicvoidremoveAccount() {
180+
AccountUtil.removeAccount(() -> {
181+
TEPIDAPI.Companion.invalidate();
182+
Intentintent =newIntent(this,StartActivity.class);
183+
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
184+
startActivity(intent);
185+
});
186+
}
187+
180188
}

‎CTF/src/main/java/ca/mcgill/science/ctf/StartActivity.java‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
packageca.mcgill.science.ctf;
22

3-
importandroid.Manifest;
43
importandroid.content.Intent;
54
importandroid.content.SharedPreferences;
65
importandroid.os.Bundle;
@@ -10,11 +9,9 @@
109
importandroid.support.v7.preference.PreferenceManager;
1110

1211
importca.allanwang.capsule.library.logging.CLog;
13-
importca.allanwang.capsule.library.permissions.CPermissionCallback;
1412
importca.mcgill.science.ctf.api.TEPIDAPI;
1513
importca.mcgill.science.ctf.auth.AccountUtil;
1614
importca.mcgill.science.ctf.fragments.SettingsFragment;
17-
importca.mcgill.science.ctf.utils.Preferences;
1815
importca.mcgill.science.ctf.utils.Utils;
1916

2017
/**
@@ -40,14 +37,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
4037
// });
4138
SharedPreferencespreferences =PreferenceManager.getDefaultSharedPreferences(this);
4239
Stringlang =preferences.getString("pref_language","en");
43-
SettingsFragment.setLocale(this,lang);//todo put setlocale somewhere else? CTFApp maybe?
40+
SettingsFragment.setLocale(this,lang);//todo put setlocale somewhere else?
4441

4542
if (AccountUtil.isSignedIn()) {
4643
AccountUtil.requestToken(this,newAccountUtil.TokenRequestCallback() {
4744
@Override
4845
publicvoidonReceived(@NonNullStringtoken) {
4946
//initialize TEPID API
50-
TEPIDAPI.Companion.setInstance(token,StartActivity.this);//to be sure, set api instance here
5147
CLog.d("Token received %s",token);
5248
launchMainActivity(token);
5349
}

‎CTF/src/main/java/ca/mcgill/science/ctf/auth/AccountUtil.java‎

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,15 @@
33
importandroid.accounts.Account;
44
importandroid.accounts.AccountManager;
55
importandroid.accounts.AccountManagerCallback;
6-
importandroid.accounts.AccountManagerFuture;
76
importandroid.app.Activity;
87
importandroid.content.Context;
98
importandroid.os.Build;
109
importandroid.os.Bundle;
1110
importandroid.support.annotation.NonNull;
12-
importandroid.support.annotation.RequiresApi;
13-
importandroid.util.Log;
1411

1512
importcom.google.gson.Gson;
1613

1714
importca.allanwang.capsule.library.logging.CLog;
18-
importca.mcgill.science.ctf.CTFApp;
1915
importca.mcgill.science.ctf.R;
2016
importca.mcgill.science.ctf.api.Session;
2117
importca.mcgill.science.ctf.api.User;
@@ -27,17 +23,24 @@ public class AccountUtil {
2723

2824
privatestaticAccountManageram;
2925
privatestaticAccountaccount;
30-
publicstaticfinalStringaccountType =CTFApp.getAppContext().getResources().getString(R.string.authenticator_account_type),
31-
tokenType =CTFApp.getAppContext().getResources().getString(R.string.authenticator_token_type),
32-
KEY_SESSION ="SESSION";
26+
publicstaticfinalStringKEY_SESSION ="SESSION";
27+
28+
publicstaticStringgetAccountType(Contextcontext) {
29+
returncontext.getResources().getString(R.string.authenticator_account_type);
30+
}
31+
32+
publicstaticStringgetTokenType(Contextcontext) {
33+
returncontext.getResources().getString(R.string.authenticator_token_type);
34+
}
3335

3436
/**
3537
* called on startup to keep a global reference to the user's account
3638
*
37-
* @param context likelyMainActivity or CTFApp
39+
* @param context likely{@link ca.mcgill.science.ctf.StartActivity}
3840
*/
3941
publicstaticvoidinitAccount(Contextcontext) {
4042
am =AccountManager.get(context);
43+
StringaccountType =getAccountType(context);
4144
if (am.getAccountsByType(accountType).length >0) {//TODO request account permission
4245
account =am.getAccountsByType(accountType)[0];
4346
}
@@ -106,13 +109,22 @@ public static void updateNick(String nick) {
106109
* removes the CTFAccount from android's account manager
107110
* used before logout to remove the account from the system
108111
*/
109-
@RequiresApi(api =Build.VERSION_CODES.LOLLIPOP_MR1)
110-
publicstaticvoidremoveAccount() {
111-
am.removeAccountExplicitly(account);
112+
publicstaticvoidremoveAccount(finalGeneralCallbackcallback) {
113+
if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.LOLLIPOP_MR1) {
114+
am.removeAccountExplicitly(account);
115+
callback.onFinish();
116+
}else {
117+
AccountManagerCallback<Boolean>handler =future ->callback.onFinish();
118+
am.removeAccount(account,handler,null);
119+
}
112120
}
113121

114122
publicstaticvoidrequestAccount(Activityactivity,AccountManagerCallback<Bundle>callback) {
115-
AccountManager.get(activity).addAccount(accountType,tokenType,null,null,activity,callback,null);
123+
AccountManager.get(activity).addAccount(getAccountType(activity),getTokenType(activity),null,null,activity,callback,null);
124+
}
125+
126+
publicinterfaceGeneralCallback {
127+
voidonFinish();
116128
}
117129

118130
publicinterfaceTokenRequestCallback {
@@ -122,12 +134,13 @@ public interface TokenRequestCallback {
122134
}
123135

124136
publicstaticvoidrequestToken(Activityactivity,@NonNullfinalTokenRequestCallbackcallback) {
125-
AccountManager.get(activity).getAuthToken(getAccount(),tokenType,null,activity,future -> {
137+
AccountManager.get(activity).getAuthToken(getAccount(),getTokenType(activity),null,activity,future -> {
126138
try {
127139
Stringtoken =future.getResult().getString(AccountManager.KEY_AUTHTOKEN);
128-
if (token ==null ||token.isEmpty())
140+
if (token ==null ||token.isEmpty()) {
141+
CLog.e("empty token received");
129142
callback.onFailed();
130-
else
143+
}else
131144
callback.onReceived(token.trim());
132145
}catch (Exceptione) {
133146
CLog.e("Failed to request token %s",e.getMessage());

‎CTF/src/main/java/ca/mcgill/science/ctf/auth/StudentAuthenticator.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public Bundle addAccount(AccountAuthenticatorResponse response, String accountTy
4242

4343
finalIntentintent =newIntent(mContext,LoginActivity.class);
4444

45-
intent.putExtra(LoginActivity.ARG_ACCOUNT_TYPE,AccountUtil.accountType);
46-
intent.putExtra(LoginActivity.ARG_TOKEN_TYPE,AccountUtil.tokenType);
45+
intent.putExtra(LoginActivity.ARG_ACCOUNT_TYPE,AccountUtil.getAccountType(mContext));
46+
intent.putExtra(LoginActivity.ARG_TOKEN_TYPE,AccountUtil.getTokenType(mContext));
4747
intent.putExtra(LoginActivity.ARG_IS_ADDING_NEW_ACCOUNT,true);
4848
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE,response);
4949

‎CTF/src/main/java/ca/mcgill/science/ctf/fragments/SettingsFragment.java‎

Lines changed: 27 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,8 @@
22

33
importandroid.app.Activity;
44
importandroid.content.Context;
5-
importandroid.content.Intent;
65
importandroid.content.res.Configuration;
7-
importandroid.os.Build;
86
importandroid.os.Bundle;
9-
importandroid.support.v7.preference.Preference;
107
importandroid.support.v7.preference.PreferenceFragmentCompat;
118

129
importorg.greenrobot.eventbus.EventBus;
@@ -17,7 +14,6 @@
1714
importca.mcgill.science.ctf.MainActivity;
1815
importca.mcgill.science.ctf.R;
1916
importca.mcgill.science.ctf.api.ITEPID;
20-
importca.mcgill.science.ctf.api.TEPIDAPI;
2117
importca.mcgill.science.ctf.auth.AccountUtil;
2218
importretrofit2.Call;
2319
importretrofit2.Callback;
@@ -42,72 +38,45 @@ public void onCreatePreferences(Bundle bundle, String s) {
4238
getPreferenceManager().setSharedPreferencesName("CAPSULE_PREFERENCES");
4339
addPreferencesFromResource(R.xml.preferences);
4440

45-
findPreference("pref_logout").setOnPreferenceClickListener(newPreference.OnPreferenceClickListener() {
46-
@Override
47-
publicbooleanonPreferenceClick(Preferencepreference) {
48-
if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.LOLLIPOP_MR1)
49-
AccountUtil.removeAccount();
50-
getActivity().finish();
51-
returntrue;
52-
}
53-
});
54-
55-
findPreference("pref_language").setOnPreferenceChangeListener(newPreference.OnPreferenceChangeListener() {
56-
@Override
57-
publicbooleanonPreferenceChange(Preferencepreference,Objecto) {
58-
if (oinstanceofString) {
59-
setLocale(getActivity(), (String)o);
60-
((MainActivity)getActivity()).reload();
61-
//todo this brings us back to the main page, want to get back to settings page (fixed 2016/12/28)
62-
}
63-
returntrue;
41+
findPreference("pref_language").setOnPreferenceChangeListener((preference,o) -> {
42+
if (oinstanceofString) {
43+
setLocale(getActivity(), (String)o);
44+
((MainActivity)getActivity()).reload();
45+
//todo this brings us back to the main page, want to get back to settings page (fixed 2016/12/28)
6446
}
47+
returntrue;
6548
});
6649

67-
findPreference("pref_theme").setOnPreferenceClickListener(newPreference.OnPreferenceClickListener() {
68-
@Override
69-
publicbooleanonPreferenceClick(Preferencepreference) {
70-
((MainActivity)getActivity()).reload();
71-
returnfalse;
72-
}
50+
findPreference("pref_theme").setOnPreferenceClickListener(preference -> {
51+
((MainActivity)getActivity()).reload();
52+
returnfalse;
7353
});
7454

75-
findPreference("pref_about").setOnPreferenceClickListener(newPreference.OnPreferenceClickListener() {
76-
@Override
77-
publicbooleanonPreferenceClick(Preferencepreference) {
78-
//TODO add about
55+
findPreference("pref_about").setOnPreferenceClickListener(preference -> {
56+
//TODO add about
7957
// Dialog dialog = new Dialog(getActivity(), "About", "...");
8058
// dialog.show();
81-
returntrue;
82-
}
59+
returntrue;
8360
});
8461

85-
findPreference("pref_logout").setOnPreferenceClickListener(newPreference.OnPreferenceClickListener() {
86-
@Override
87-
publicbooleanonPreferenceClick(Preferencepreference) {
88-
mAPI.removeSession(AccountUtil.getSession().get_id()).enqueue(newCallback<Void>() {
89-
@Override
90-
publicvoidonResponse(Call<Void>call,Response<Void>response) {
91-
relaunchLogin();
92-
}
93-
94-
@Override
95-
publicvoidonFailure(Call<Void>call,Throwablet) {
96-
relaunchLogin();
97-
}
98-
});
99-
returnfalse;
100-
}
62+
findPreference("pref_logout").setOnPreferenceClickListener(preference -> {
63+
mAPI.removeSession(AccountUtil.getSession().get_id()).enqueue(newCallback<Void>() {
64+
@Override
65+
publicvoidonResponse(Call<Void>call,Response<Void>response) {
66+
logout();
67+
}
68+
69+
@Override
70+
publicvoidonFailure(Call<Void>call,Throwablet) {
71+
logout();//TODO notify user and don't actually logout?
72+
}
73+
});
74+
returnfalse;
10175
});
10276
}
10377

104-
privatevoidrelaunchLogin() {
105-
if (Build.VERSION.SDK_INT >=Build.VERSION_CODES.LOLLIPOP_MR1)
106-
AccountUtil.removeAccount();
107-
TEPIDAPI.Companion.invalidate();
108-
Intentintent =newIntent(this.getContext(),MainActivity.class);
109-
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
110-
startActivity(intent);
78+
privatevoidlogout() {
79+
((MainActivity)getActivity()).removeAccount();
11180
}
11281

11382
/**

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp