Skip to content

Commit

Permalink
feat(core): manage schedule inventory with deeplink and qrcode
Browse files Browse the repository at this point in the history
Signed-off-by: Teclib <[email protected]>
  • Loading branch information
stonebuzz committed Jan 7, 2020
1 parent 175f2e3 commit bed1bac
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 24 deletions.
6 changes: 3 additions & 3 deletions app/src/main/assets/about.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
about.version=1.0.0-rc.2
about.build=39231
about.date=Mon Jan 06 08:27:40 2020
about.commit=0b1deb0
about.commitFull=0b1deb0e818cf96ff43f484397950b2182094b6d
about.date=lun. janv. 06 09:59:33 2020
about.commit=
about.commitFull=
about.github=https://github.com/glpi-project/android-inventory-agent
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Base64;
import android.view.View;
import android.widget.Button;
Expand All @@ -51,7 +52,6 @@

import com.google.android.material.floatingactionbutton.FloatingActionButton;

import org.flyve.inventory.CommonErrorType;
import org.flyve.inventory.InventoryLog;
import org.glpi.inventory.agent.R;
import org.glpi.inventory.agent.core.detailserver.DetailServer;
Expand All @@ -62,7 +62,7 @@
import org.glpi.inventory.agent.utils.Utils;
import org.json.JSONObject;

import java.nio.charset.StandardCharsets;
import android.net.Uri;
import java.util.ArrayList;

import static android.view.View.GONE;
Expand All @@ -78,6 +78,7 @@ public class ActivityDetailServer extends AppCompatActivity implements DetailSer
private EditText editPassWord;
private Toolbar toolbar;
private String serverName;
private JSONObject extra_Data = null;
private FloatingActionButton btnScan;

private static final int REQUEST_CODE_SCAN = 150;
Expand Down Expand Up @@ -118,31 +119,31 @@ public void onClick(View view) {
Intent intent = getIntent();

if(intent != null){
Uri data;
data = intent.getData();

if(data != null){
Uri deeplink_Data = null;
deeplink_Data = intent.getData();

if(deeplink_Data != null){
try {
deeplink = data.getQueryParameter("data");
deeplink = deeplink_Data.getQueryParameter("data");
//decode base64
byte[] decodedBytes = Base64.decode(deeplink,Base64.DEFAULT);
String decodedString = new String(decodedBytes);

// come from QR scan
JSONObject jsonData = null;
try {
jsonData = new JSONObject(decodedString);
extra_Data = new JSONObject(decodedString);
} catch (Exception e) {
Toast.makeText(this, getApplicationContext().getResources().getString(R.string.bad_deeplink_format), Toast.LENGTH_LONG).show();
AgentLog.e(getApplicationContext().getResources().getString(R.string.bad_deeplink_format)+ " " + decodedString);
}

if(jsonData != null){
if(extra_Data != null){
try {
editUrlAddress.setText(jsonData.getString("URL"));
editTag.setText(jsonData.getString("TAG"));
editLogin.setText(jsonData.getString("LOGIN"));
editPassWord.setText(jsonData.getString("PASSWORD"));
editUrlAddress.setText(extra_Data.getString("URL"));
editTag.setText(extra_Data.getString("TAG"));
editLogin.setText(extra_Data.getString("LOGIN"));
editPassWord.setText(extra_Data.getString("PASSWORD"));
} catch (Exception ex) {
Toast.makeText(this, getApplicationContext().getResources().getString(R.string.bad_deeplink_format), Toast.LENGTH_LONG).show();
AgentLog.e(getApplicationContext().getResources().getString(R.string.bad_deeplink_format));
Expand All @@ -167,20 +168,20 @@ public void onActivityResult(final int requestCode, final int resultCode, final
String decodedString = new String(decodedBytes);

// come from QR scan
JSONObject jsonData = null;

try {
jsonData = new JSONObject(decodedString);
extra_Data = new JSONObject(decodedString);
} catch (Exception e) {
Toast.makeText(this, getApplicationContext().getResources().getString(R.string.bad_qr_code_format), Toast.LENGTH_LONG).show();
AgentLog.e(getApplicationContext().getResources().getString(R.string.bad_qr_code_format)+ " " + decodedString);
}

if(jsonData != null){
if(extra_Data != null){
try {
editUrlAddress.setText(jsonData.getString("URL"));
editTag.setText(jsonData.getString("TAG"));
editLogin.setText(jsonData.getString("LOGIN"));
editPassWord.setText(jsonData.getString("PASSWORD"));
editUrlAddress.setText(extra_Data.getString("URL"));
editTag.setText(extra_Data.getString("TAG"));
editLogin.setText(extra_Data.getString("LOGIN"));
editPassWord.setText(extra_Data.getString("PASSWORD"));
} catch (Exception ex) {
Toast.makeText(this, getApplicationContext().getResources().getString(R.string.bad_qr_code_format), Toast.LENGTH_LONG).show();
AgentLog.e(getApplicationContext().getResources().getString(R.string.bad_qr_code_format));
Expand Down Expand Up @@ -231,6 +232,20 @@ public void onClick(View v) {
serverInfo.add(editPassWord.getText().toString());
if (serverName == null) {
presenter.saveServer(serverInfo, getApplicationContext());
//manage automatic inventory
if(extra_Data != null){
try {
if(extra_Data.getString("ANDROID_AUTOMATIC_INVENTORY").equalsIgnoreCase("1")){
SharedPreferences customSharedPreference = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = customSharedPreference.edit();
editor.putString("timeInventory", extra_Data.getString("ANDROID_FREQUENCY"));
editor.putBoolean("autoStartInventory", true);
editor.apply();
}
} catch (Exception ex) {
AgentLog.e(getApplicationContext().getResources().getString(R.string.bad_qr_code_format));
}
}
} else {
presenter.updateServer(serverInfo, serverName, getApplicationContext());
}
Expand Down

0 comments on commit bed1bac

Please sign in to comment.