Merge pull request #2454 from schleif/security-key-shop

Implementation of Cotech Security Keys shop
This commit is contained in:
Dominik Schürmann 2019-10-22 16:15:12 +02:00 committed by GitHub
commit 5b8b985e61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 126 additions and 0 deletions

View File

@ -106,6 +106,7 @@ dependencies {
annotationProcessor "android.arch.lifecycle:compiler:1.0.0"
compile "android.arch.persistence:db-framework:1.0.0"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
// for debugging the db. don't enable by default, this will expose the database no the network!
// debugImplementation 'com.amitshekhar.android:debug-db:1.0.3'

View File

@ -18,6 +18,7 @@
package org.sufficientlysecure.keychain.ui;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.Bundle;
@ -56,6 +57,7 @@ public class MainActivity extends BaseSecurityTokenActivity implements FabContai
public static final int ID_TRANSFER = 5;
static final int ID_SETTINGS = 6;
static final int ID_HELP = 7;
static final int ID_SHOP = 8;
// both of these are used for instrumentation testing only
public static final String EXTRA_SKIP_FIRST_TIME = "skip_first_time";
@ -81,6 +83,8 @@ public class MainActivity extends BaseSecurityTokenActivity implements FabContai
.withHeader(R.layout.main_drawer_header)
.withToolbar(mToolbar)
.addDrawerItems(
new PrimaryDrawerItem().withName(R.string.nav_shop).withIcon(CommunityMaterial.Icon.cmd_shopping)
.withIdentifier(ID_SHOP).withSelectable(false).withTypeface(Typeface.DEFAULT_BOLD),
new PrimaryDrawerItem().withName(R.string.nav_keys).withIcon(CommunityMaterial.Icon.cmd_key)
.withIdentifier(ID_KEYS).withSelectable(false),
new PrimaryDrawerItem().withName(R.string.nav_encrypt_decrypt).withIcon(FontAwesome.Icon.faw_lock)
@ -126,6 +130,9 @@ public class MainActivity extends BaseSecurityTokenActivity implements FabContai
case ID_HELP:
intent = new Intent(MainActivity.this, HelpActivity.class);
break;
case ID_SHOP:
onShopSelected();
break;
}
if (intent != null) {
MainActivity.this.startActivity(intent);
@ -252,6 +259,13 @@ public class MainActivity extends BaseSecurityTokenActivity implements FabContai
}
}
private void onShopSelected() {
mToolbar.setTitle("Cotech Security Keys");
mDrawer.setSelection(ID_SHOP, false);
Fragment frag = new SecurityKeyShopFragment();
setFragment(frag);
}
@Override
protected void onSaveInstanceState(Bundle outState) {
// add the values which need to be saved from the drawer to the bundle

View File

@ -0,0 +1,71 @@
/*
* Copyright (C) 2017 Schürmann & Breitmoser GbR
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package org.sufficientlysecure.keychain.ui;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
import android.widget.TextView;
import org.sufficientlysecure.keychain.R;
public class SecurityKeyShopFragment extends Fragment {
public static final String webShopURL = "https://shop.cotech.de/";
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.security_key_shop_fragment, container, false);
WebView webView = view.findViewById(R.id.shop_webView);
webView.setWebViewClient(new SecurityKeyShopWebViewClient(
view.findViewById(R.id.shop_progressbar),
view.findViewById(R.id.shop_progressbar_label)
));
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl(webShopURL);
return view;
}
class SecurityKeyShopWebViewClient extends WebViewClient {
private ProgressBar progressBar;
private TextView progressBarLabel;
SecurityKeyShopWebViewClient(ProgressBar progressBar, TextView progressBarLabel) {
this.progressBar = progressBar;
this.progressBarLabel = progressBarLabel;
progressBar.setVisibility(View.VISIBLE);
progressBarLabel.setVisibility(View.VISIBLE);
}
@Override
public void onPageCommitVisible(WebView view, String url) {
super.onPageCommitVisible(view, url);
progressBar.setVisibility(View.GONE);
progressBarLabel.setVisibility(View.GONE);
}
}
}

View File

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
android:id="@+id/shop_webView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<ProgressBar
android:id="@+id/shop_progressbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="@+id/shop_webView"
app:layout_constraintEnd_toEndOf="@+id/shop_webView"
app:layout_constraintStart_toStartOf="@+id/shop_webView"
app:layout_constraintTop_toTopOf="@+id/shop_webView" />
<TextView
android:id="@+id/shop_progressbar_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shop_loading_label"
app:layout_constraintEnd_toEndOf="@+id/shop_progressbar"
app:layout_constraintStart_toStartOf="@+id/shop_progressbar"
app:layout_constraintTop_toBottomOf="@+id/shop_progressbar" />
</android.support.constraint.ConstraintLayout>

View File

@ -857,6 +857,7 @@
<string name="my_keys">"My Keys"</string>
<string name="nav_backup">"Backup/Restore"</string>
<string name="nav_transfer">"Secure Wifi Transfer"</string>
<string name="nav_shop">Shop</string>
<!-- hints -->
<string name="encrypt_content_edit_text_hint">"Type text"</string>
@ -1967,4 +1968,6 @@
<string name="subkey_action_expiry_date">Expiry will change to %s</string>
<string name="share_key_clipboard">Share key via clipboard</string>
<string name="share_key">Share key</string>
<string name="shop_loading_label">Loading shop...</string>
</resources>