-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
96 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package fr.gaulupeau.apps.Poche.ui.preferences; | ||
|
||
import android.app.Activity; | ||
import android.content.ActivityNotFoundException; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.net.Uri; | ||
import android.os.Bundle; | ||
import androidx.annotation.Nullable; | ||
import androidx.fragment.app.Fragment; | ||
|
@@ -36,6 +38,8 @@ public class ConnectionWizardActivity extends BaseActionBarActivity { | |
|
||
private static final String TAG = "ConnectionWizard"; | ||
|
||
private static final int REQUEST_CODE_QR_CODE = 1; | ||
|
||
private static final String DATA_PROVIDER = "provider"; | ||
private static final String DATA_URL = "url"; | ||
private static final String DATA_USERNAME = "username"; | ||
|
@@ -95,6 +99,7 @@ protected void onCreate(Bundle savedInstanceState) { | |
|
||
url = connectionData.url; | ||
username = connectionData.username; | ||
password = connectionData.password; | ||
|
||
fillOutData = true; | ||
} catch(IllegalArgumentException e) { | ||
|
@@ -152,6 +157,33 @@ protected void onCreate(Bundle savedInstanceState) { | |
} | ||
} | ||
|
||
@Override | ||
protected void onActivityResult(int requestCode, int resultCode, Intent data) { | ||
super.onActivityResult(requestCode, resultCode, data); | ||
|
||
if(requestCode == REQUEST_CODE_QR_CODE) { | ||
if(resultCode == RESULT_OK) { | ||
String resultString = data.getStringExtra("SCAN_RESULT"); | ||
Log.d(TAG, "onActivityResult() got string: " + resultString); | ||
|
||
if(resultString == null) return; | ||
|
||
Uri uri = Uri.parse(resultString); | ||
if(!"wallabag".equals(uri.getScheme())) { | ||
Log.i(TAG, "onActivityResult() unrecognized URI scheme: " + uri.getScheme()); | ||
Toast.makeText(this, R.string.connectionWizard_misc_incorrectConnectionURI, | ||
Toast.LENGTH_SHORT).show(); | ||
return; | ||
} | ||
|
||
Intent intent = getIntent(); | ||
intent.setData(uri); | ||
startActivity(intent); | ||
finish(); | ||
} | ||
} | ||
} | ||
|
||
private ConnectionData parseLoginData(String connectionUri) { | ||
// wallabag://[email protected] | ||
String prefix = "wallabag://"; | ||
|
@@ -170,7 +202,35 @@ private ConnectionData parseLoginData(String connectionUri) { | |
throw new IllegalArgumentException("Illegal number of login URL elements detected: " + values.length); | ||
} | ||
|
||
return new ConnectionData(values[0], values[1]); | ||
String username = values[0]; | ||
String password = null; | ||
if(username.contains(":")) { | ||
int index = username.indexOf(":"); | ||
password = username.substring(index + 1); | ||
username = username.substring(0, index); | ||
} | ||
|
||
return new ConnectionData(username, password, values[1]); | ||
} | ||
|
||
private void scanQrCode() { | ||
try { | ||
Intent intent = new Intent("com.google.zxing.client.android.SCAN"); | ||
intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); | ||
|
||
startActivityForResult(intent, REQUEST_CODE_QR_CODE); | ||
} catch(ActivityNotFoundException e) { | ||
Log.i(TAG, "scanQrCode() exception", e); | ||
|
||
Toast.makeText(this, R.string.connectionWizard_misc_installQrCodeScanner, | ||
Toast.LENGTH_LONG).show(); | ||
|
||
Uri marketUri = Uri.parse("market://details?id=de.markusfisch.android.binaryeye"); | ||
Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri); | ||
startActivity(marketIntent); | ||
} catch(Exception e) { | ||
Log.w(TAG, "scanQrCode() exception", e); | ||
} | ||
} | ||
|
||
public void prev(WizardPageFragment fragment, Bundle bundle) { | ||
|
@@ -346,6 +406,16 @@ protected int getLayoutResourceID() { | |
return R.layout.connection_wizard_provider_selection_fragment; | ||
} | ||
|
||
@Override | ||
protected void initButtons(View v) { | ||
super.initButtons(v); | ||
|
||
Button scanCodeButton = (Button)v.findViewById(R.id.scanQrCodeButton); | ||
if(scanCodeButton != null) { | ||
scanCodeButton.setOnClickListener(v1 -> activity.scanQrCode()); | ||
} | ||
} | ||
|
||
@Override | ||
protected void nextButtonPressed() { | ||
Bundle bundle = getArguments(); | ||
|
@@ -628,10 +698,12 @@ protected void saveSettings() { | |
|
||
private class ConnectionData { | ||
String username; | ||
String password; | ||
String url; | ||
|
||
ConnectionData(String username, String url) { | ||
ConnectionData(String username, String password, String url) { | ||
this.username = username; | ||
this.password = password; | ||
this.url = url; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#000" | ||
android:pathData="M3,11H5V13H3V11M11,5H13V9H11V5M9,11H13V15H11V13H9V11M15,11H17V13H19V11H21V13H19V15H21V19H19V21H17V19H13V21H11V17H15V15H17V13H15V11M19,19V15H17V19H19M15,3H21V9H15V3M17,5V7H19V5H17M3,3H9V9H3V3M5,5V7H7V5H5M3,15H9V21H3V15M5,17V19H7V17H5Z" /> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters