WIP: Refactored NFC fragment to view.
This commit is contained in:
parent
1fd6e447af
commit
97994c5e43
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<org.fdroid.fdroid.views.swap.views.NfcView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@ -30,4 +30,4 @@
|
|||||||
android:layout_below="@+id/text_description"
|
android:layout_below="@+id/text_description"
|
||||||
android:layout_centerHorizontal="true"/>
|
android:layout_centerHorizontal="true"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</org.fdroid.fdroid.views.swap.views.NfcView>
|
@ -16,11 +16,15 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import org.fdroid.fdroid.FDroidApp;
|
import org.fdroid.fdroid.FDroidApp;
|
||||||
|
import org.fdroid.fdroid.NfcHelper;
|
||||||
|
import org.fdroid.fdroid.Preferences;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
import org.fdroid.fdroid.localrepo.LocalRepoManager;
|
import org.fdroid.fdroid.localrepo.LocalRepoManager;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.Timer;
|
||||||
|
import java.util.TimerTask;
|
||||||
|
|
||||||
public class SwapWorkflowActivity extends FragmentActivity {
|
public class SwapWorkflowActivity extends FragmentActivity {
|
||||||
|
|
||||||
@ -39,6 +43,7 @@ public class SwapWorkflowActivity extends FragmentActivity {
|
|||||||
private InnerView currentView;
|
private InnerView currentView;
|
||||||
private boolean hasPreparedLocalRepo = false;
|
private boolean hasPreparedLocalRepo = false;
|
||||||
private UpdateAsyncTask updateSwappableAppsTask = null;
|
private UpdateAsyncTask updateSwappableAppsTask = null;
|
||||||
|
private Timer shutdownLocalRepoTimer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -108,10 +113,60 @@ public class SwapWorkflowActivity extends FragmentActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onJoinWifiComplete() {
|
public void onJoinWifiComplete() {
|
||||||
/*ensureLocalRepoRunning();
|
ensureLocalRepoRunning();
|
||||||
if (!attemptToShowNfc()) {
|
if (!attemptToShowNfc()) {
|
||||||
showWifiQr();
|
// showWifiQr();
|
||||||
}*/
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean attemptToShowNfc() {
|
||||||
|
// TODO: What if NFC is disabled? Hook up with NfcNotEnabledActivity? Or maybe only if they
|
||||||
|
// click a relevant button?
|
||||||
|
|
||||||
|
// Even if they opted to skip the message which says "Touch devices to swap",
|
||||||
|
// we still want to actually enable the feature, so that they could touch
|
||||||
|
// during the wifi qr code being shown too.
|
||||||
|
boolean nfcMessageReady = NfcHelper.setPushMessage(this, Utils.getSharingUri(FDroidApp.repo));
|
||||||
|
|
||||||
|
if (Preferences.get().showNfcDuringSwap() && nfcMessageReady) {
|
||||||
|
inflateInnerView(R.layout.swap_nfc);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ensureLocalRepoRunning() {
|
||||||
|
if (!FDroidApp.isLocalRepoServiceRunning()) {
|
||||||
|
FDroidApp.startLocalRepoService(this);
|
||||||
|
initLocalRepoTimer(900000); // 15 mins
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initLocalRepoTimer(long timeoutMilliseconds) {
|
||||||
|
|
||||||
|
// reset the timer if viewing this Activity again
|
||||||
|
if (shutdownLocalRepoTimer != null)
|
||||||
|
shutdownLocalRepoTimer.cancel();
|
||||||
|
|
||||||
|
// automatically turn off after 15 minutes
|
||||||
|
shutdownLocalRepoTimer = new Timer();
|
||||||
|
shutdownLocalRepoTimer.schedule(new TimerTask() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
FDroidApp.stopLocalRepoService(SwapWorkflowActivity.this);
|
||||||
|
}
|
||||||
|
}, timeoutMilliseconds);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopSwapping() {
|
||||||
|
if (FDroidApp.isLocalRepoServiceRunning()) {
|
||||||
|
if (shutdownLocalRepoTimer != null) {
|
||||||
|
shutdownLocalRepoTimer.cancel();
|
||||||
|
}
|
||||||
|
FDroidApp.stopLocalRepoService(SwapWorkflowActivity.this);
|
||||||
|
}
|
||||||
|
finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
class UpdateAsyncTask extends AsyncTask<Void, String, Void> {
|
class UpdateAsyncTask extends AsyncTask<Void, String, Void> {
|
||||||
|
65
F-Droid/src/org/fdroid/fdroid/views/swap/views/NfcView.java
Normal file
65
F-Droid/src/org/fdroid/fdroid/views/swap/views/NfcView.java
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
package org.fdroid.fdroid.views.swap.views;
|
||||||
|
|
||||||
|
import android.annotation.TargetApi;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.v4.view.MenuItemCompat;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.RelativeLayout;
|
||||||
|
|
||||||
|
import org.fdroid.fdroid.Preferences;
|
||||||
|
import org.fdroid.fdroid.R;
|
||||||
|
import org.fdroid.fdroid.views.swap.SwapWorkflowActivity;
|
||||||
|
|
||||||
|
public class NfcView extends RelativeLayout implements SwapWorkflowActivity.InnerView {
|
||||||
|
|
||||||
|
public NfcView(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NfcView(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NfcView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
|
public NfcView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onFinishInflate() {
|
||||||
|
super.onFinishInflate();
|
||||||
|
CheckBox dontShowAgain = (CheckBox)findViewById(R.id.checkbox_dont_show);
|
||||||
|
dontShowAgain.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
|
Preferences.get().setShowNfcDuringSwap(!isChecked);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
|
||||||
|
inflater.inflate(R.menu.swap_skip, menu);
|
||||||
|
MenuItem next = menu.findItem(R.id.action_next);
|
||||||
|
MenuItemCompat.setShowAsAction(next, MenuItemCompat.SHOW_AS_ACTION_ALWAYS | MenuItemCompat.SHOW_AS_ACTION_WITH_TEXT);
|
||||||
|
next.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
// TODO: Show QR Code.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user