Skip to content
This repository was archived by the owner on Nov 7, 2023. It is now read-only.

Commit a76ffc9

Browse files
author
Ryan Berg
committed
add guide when no TOTP codes registered
1 parent bc41bf0 commit a76ffc9

6 files changed

Lines changed: 101 additions & 12 deletions

File tree

app/src/main/java/co/krypt/krypton/crypto/TOTP.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import javax.crypto.Mac;
1717
import javax.crypto.spec.SecretKeySpec;
1818

19-
import co.krypt.krypton.db.OpenDatabaseHelper;
2019
import co.krypt.krypton.exception.CryptoException;
2120
import co.krypt.krypton.silo.IdentityService;
2221
import co.krypt.krypton.silo.Silo;

app/src/main/java/co/krypt/krypton/devices/DevicesFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
8686
public void onClick(View v) {
8787
Activity activity = getActivity();
8888
if (activity instanceof MainActivity) {
89-
((MainActivity) activity).setActiveTab(MainActivity.PAIR_FRAGMENT_POSITION);
89+
((MainActivity) activity).setActiveTab(MainActivity.SCAN_FRAGMENT_POSITION);
9090
}
9191
}
9292
});

app/src/main/java/co/krypt/krypton/help/HelpFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public void onClick(View v) {
4949
mainActivity.getSupportFragmentManager().beginTransaction()
5050
.setCustomAnimations(R.anim.enter_from_bottom, R.anim.exit_to_bottom)
5151
.hide(self).remove(self).commit();
52-
mainActivity.setActiveTab(MainActivity.PAIR_FRAGMENT_POSITION);
52+
mainActivity.setActiveTab(MainActivity.SCAN_FRAGMENT_POSITION);
5353
}
5454
}
5555
});

app/src/main/java/co/krypt/krypton/totp/TOTPAccountsFragment.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,14 @@
3737
import co.krypt.krypton.exception.CryptoException;
3838
import co.krypt.krypton.silo.IdentityService;
3939
import co.krypt.krypton.uiutils.Icons;
40+
import co.krypt.kryptonite.MainActivity;
4041

4142
public class TOTPAccountsFragment extends Fragment {
4243
private static final String TAG = "TOTPAccountsFragment";
4344

4445
private RecyclerView totpAccounts;
4546
private TOTPRecyclerViewAdapter totpAccountsAdapter;
47+
private View noCodesContainer;
4648

4749
public TOTPAccountsFragment() { }
4850

@@ -65,7 +67,13 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
6567
totpAccounts = v.findViewById(R.id.totpAccounts);
6668
totpAccounts.setAdapter(totpAccountsAdapter);
6769
totpAccounts.setLayoutManager(new LinearLayoutManager(getContext()));
70+
noCodesContainer = v.findViewById(R.id.totpEmptyContainer);
71+
v.findViewById(R.id.scanTOTPButton).setOnClickListener((event) -> {
72+
MainActivity activity = (MainActivity) getActivity();
73+
activity.setActiveTab(MainActivity.SCAN_FRAGMENT_POSITION);
74+
});
6875
EventBus.getDefault().register(this);
76+
refreshAccounts(null);
6977
return v;
7078
}
7179

@@ -80,6 +88,11 @@ public void refreshAccounts(IdentityService.TOTPAccountsUpdated _) {
8088
try {
8189
totpAccountsAdapter.accounts = TOTP.getAccounts(getContext());
8290
totpAccountsAdapter.notifyDataSetChanged();
91+
if (!totpAccountsAdapter.accounts.isEmpty()) {
92+
noCodesContainer.setVisibility(View.GONE);
93+
} else {
94+
noCodesContainer.setVisibility(View.VISIBLE);
95+
}
8396
}
8497
catch (SQLException e) {
8598
e.printStackTrace();

app/src/main/java/co/krypt/kryptonite/MainActivity.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public class MainActivity extends AppCompatActivity {
6262
private static final String TAG = "MainActivity";
6363
public static final int KEYS_FRAGMENT_POSITION = 0;
6464
public static final int CODES_FRAGMENT_POSITION = 1;
65-
public static final int PAIR_FRAGMENT_POSITION = 2;
65+
public static final int SCAN_FRAGMENT_POSITION = 2;
6666
public static final int DEVICES_FRAGMENT_POSITION = 3;
6767
public static final int DEVELOPER_FRAGMENT_POSITION = 4;
6868
public static final int TEAM_FRAGMENT_POSITION = 5;
@@ -219,7 +219,7 @@ public void setTabIcons() {
219219
TabLayout tabLayout = (TabLayout) findViewById(R.id.tabs);
220220
TabLayout.Tab keysTab = tabLayout.getTabAt(KEYS_FRAGMENT_POSITION);
221221
TabLayout.Tab codesTab = tabLayout.getTabAt(CODES_FRAGMENT_POSITION);
222-
TabLayout.Tab pairTab = tabLayout.getTabAt(PAIR_FRAGMENT_POSITION);
222+
TabLayout.Tab pairTab = tabLayout.getTabAt(SCAN_FRAGMENT_POSITION);
223223
TabLayout.Tab deviceTab = tabLayout.getTabAt(DEVICES_FRAGMENT_POSITION);
224224
TabLayout.Tab developerTab = tabLayout.getTabAt(DEVELOPER_FRAGMENT_POSITION);
225225
if(keysTab != null) {
@@ -276,7 +276,7 @@ private void postActivePage(int position) {
276276
case CODES_FRAGMENT_POSITION:
277277
new Analytics(getApplicationContext()).postPageView("Codes");
278278
break;
279-
case PAIR_FRAGMENT_POSITION:
279+
case SCAN_FRAGMENT_POSITION:
280280
new Analytics(getApplicationContext()).postPageView("Pair");
281281
break;
282282
case DEVICES_FRAGMENT_POSITION:
@@ -324,7 +324,7 @@ public Fragment getItem(int position) {
324324
return keysFragment;
325325
case CODES_FRAGMENT_POSITION:
326326
return codesFragment;
327-
case PAIR_FRAGMENT_POSITION:
327+
case SCAN_FRAGMENT_POSITION:
328328
return pairFragment;
329329
case DEVICES_FRAGMENT_POSITION:
330330
return devicesFragment;
@@ -357,7 +357,7 @@ public CharSequence getPageTitle(int position) {
357357
return "Security Keys";
358358
case CODES_FRAGMENT_POSITION:
359359
return "Backup Codes";
360-
case PAIR_FRAGMENT_POSITION:
360+
case SCAN_FRAGMENT_POSITION:
361361
return "Scan";
362362
case DEVICES_FRAGMENT_POSITION:
363363
return "Computers";
Lines changed: 81 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,83 @@
1-
<android.support.v7.widget.RecyclerView
1+
2+
<android.support.constraint.ConstraintLayout
23
xmlns:android="http://schemas.android.com/apk/res/android"
3-
android:id="@+id/totpAccounts"
4+
xmlns:app="http://schemas.android.com/apk/res-auto"
5+
android:id="@+id/root"
46
android:layout_width="match_parent"
5-
android:layout_height="match_parent"
6-
android:background="@color/appBlueGrayBackground" />
7+
android:layout_height="match_parent">
8+
9+
<android.support.v7.widget.RecyclerView
10+
android:id="@+id/totpAccounts"
11+
android:layout_width="match_parent"
12+
android:layout_height="match_parent"
13+
android:background="@color/appBlueGrayBackground" />
14+
15+
<android.support.constraint.ConstraintLayout
16+
android:id="@+id/totpEmptyContainer"
17+
android:layout_width="0dp"
18+
android:layout_height="wrap_content"
19+
android:layout_marginStart="8dp"
20+
android:layout_marginEnd="8dp"
21+
android:background="@drawable/corners"
22+
app:layout_constraintBottom_toBottomOf="parent"
23+
app:layout_constraintEnd_toEndOf="parent"
24+
app:layout_constraintStart_toStartOf="parent"
25+
app:layout_constraintTop_toTopOf="parent">
26+
27+
<android.support.v7.widget.AppCompatImageView
28+
android:id="@+id/codesImage"
29+
android:layout_width="50dp"
30+
android:layout_height="50dp"
31+
android:layout_marginTop="16dp"
32+
app:layout_constraintEnd_toEndOf="parent"
33+
app:layout_constraintStart_toStartOf="parent"
34+
app:layout_constraintTop_toTopOf="parent"
35+
app:srcCompat="@drawable/codes" />
36+
37+
<android.support.v7.widget.AppCompatTextView
38+
android:id="@+id/noCodesHeader"
39+
android:layout_width="wrap_content"
40+
android:layout_height="wrap_content"
41+
android:fontFamily="@font/open_sans_bold"
42+
android:text="No Registered Codes"
43+
android:textColor="@color/appBlack"
44+
android:textSize="16sp"
45+
app:layout_constraintEnd_toEndOf="parent"
46+
app:layout_constraintStart_toStartOf="parent"
47+
app:layout_constraintTop_toBottomOf="@+id/codesImage" />
48+
49+
<android.support.v7.widget.AppCompatTextView
50+
android:id="@+id/noCodesText"
51+
android:layout_width="wrap_content"
52+
android:layout_height="wrap_content"
53+
android:fontFamily="@font/open_sans_semibold"
54+
android:text="Scan an authenticator QR code to register"
55+
android:textColor="@color/appBlack"
56+
app:layout_constraintEnd_toEndOf="parent"
57+
app:layout_constraintStart_toStartOf="parent"
58+
app:layout_constraintTop_toBottomOf="@+id/noCodesHeader" />
59+
60+
<android.support.v7.widget.AppCompatButton
61+
android:id="@+id/scanTOTPButton"
62+
android:layout_width="wrap_content"
63+
android:layout_height="wrap_content"
64+
android:layout_marginTop="16dp"
65+
android:layout_marginBottom="24dp"
66+
android:background="@drawable/flat_button"
67+
android:backgroundTint="@color/appGreen"
68+
android:fontFamily="@font/open_sans_bold"
69+
android:paddingStart="16dp"
70+
android:paddingEnd="16dp"
71+
android:text="Scan"
72+
android:textAllCaps="false"
73+
android:textColor="@color/appGreen"
74+
android:textSize="16sp"
75+
android:textStyle="normal|bold"
76+
app:layout_constraintBottom_toBottomOf="parent"
77+
app:layout_constraintEnd_toEndOf="parent"
78+
app:layout_constraintStart_toStartOf="parent"
79+
app:layout_constraintTop_toBottomOf="@+id/noCodesText" />
80+
</android.support.constraint.ConstraintLayout>
81+
82+
83+
</android.support.constraint.ConstraintLayout>

0 commit comments

Comments
 (0)