Skip to content

Commit

Permalink
Added guided tour struct at webview activity (Escola-em-Casa#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
markinlimac committed Oct 14, 2020
1 parent e112d51 commit a624cd2
Showing 1 changed file with 127 additions and 0 deletions.
127 changes: 127 additions & 0 deletions app/src/main/java/org/cordova/quasar/corona/app/WebviewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import smartdevelop.ir.eram.showcaseviewlib.GuideView;
import smartdevelop.ir.eram.showcaseviewlib.config.DismissType;
import smartdevelop.ir.eram.showcaseviewlib.config.Gravity;
import smartdevelop.ir.eram.showcaseviewlib.listener.GuideListener;

import android.content.SharedPreferences;

public class WebviewActivity extends AppCompatActivity {
private WebView myWebView;
private String url;
Expand All @@ -75,6 +82,90 @@ private File createImageFile() throws IOException {
return imageFile;
}

private void checkClassroomFirstRun() {
final String PREFS_NAME = "classroom_first_run";
final String PREF_VERSION_CODE_KEY = "1.0";
final int DOESNT_EXIST = -1;

// Get current version code
int currentVersionCode = BuildConfig.VERSION_CODE;

// Get saved version code
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
int savedVersionCode = prefs.getInt(PREF_VERSION_CODE_KEY, DOESNT_EXIST);

// Check for first run or upgrade
if (currentVersionCode == savedVersionCode) {

// This is just a normal run
return;

} else if (savedVersionCode == DOESNT_EXIST) {
new GuideView.Builder(this)
.setTitle("Google Classroom")
.setContentText("Esta aba serve para acessar sua conta do google classrom")
.setGravity(Gravity.auto) //optional
.setDismissType(DismissType.anywhere) //optional - default DismissType.targetView
.setTargetView(findViewById(R.id.classroom))
.setContentTextSize(12)//optional
.setTitleTextSize(14)//optional
.build()
.show();
} else if (currentVersionCode > savedVersionCode) {
new GuideView.Builder(this)
.setTitle("Google Classroom")
.setContentText("Esta aba serve para acessar sua conta do google classrom")
.setGravity(Gravity.auto) //optional
.setDismissType(DismissType.anywhere) //optional - default DismissType.targetView
.setTargetView(findViewById(R.id.classroom))
.setContentTextSize(12)//optional
.setTitleTextSize(14)//optional
.build()
.show();
}

// Update the shared preferences with the current version code
prefs.edit().putInt(PREF_VERSION_CODE_KEY, currentVersionCode).apply();
}

private void checkWikipediaFirstRun() {
final String PREFS_NAME = "wikipedia_first_run";
final String PREF_VERSION_CODE_KEY = "1.0";
final int DOESNT_EXIST = -1;

// Get current version code
int currentVersionCode = BuildConfig.VERSION_CODE;

// Get saved version code
SharedPreferences prefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
int savedVersionCode = prefs.getInt(PREF_VERSION_CODE_KEY, DOESNT_EXIST);

// Check for first run or upgrade
if (currentVersionCode == savedVersionCode) {

// This is just a normal run
return;

} else if (savedVersionCode == DOESNT_EXIST) {
new GuideView.Builder(this)
.setTitle("Wikipedia")
.setContentText("Esta aba serve para acessar a wikipedia")
.setGravity(Gravity.auto) //optional
.setDismissType(DismissType.anywhere) //optional - default DismissType.targetView
.setTargetView(findViewById(R.id.wikipedia))
.setContentTextSize(12)//optional
.setTitleTextSize(14)//optional
.build()
.show();
} else if (currentVersionCode > savedVersionCode) {

// TODO This is an upgrade
}

// Update the shared preferences with the current version code
prefs.edit().putInt(PREF_VERSION_CODE_KEY, currentVersionCode).apply();
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down Expand Up @@ -159,6 +250,12 @@ protected void onCreate(Bundle savedInstanceState) {

url = getIntent().getStringExtra("url");
myWebView.loadUrl(url);

if (url.equals("https://classroom.google.com/a/estudante.se.df.gov.br")) {
checkClassroomFirstRun();
} else if (url.equals("https://pt.wikipedia.org/")) {
checkWikipediaFirstRun();
}
}

@Override
Expand Down Expand Up @@ -287,6 +384,36 @@ protected void onResume() {
break;
}
}
// if (sPreferences.getBoolean("firstRun", true)) {
// sPreferences.edit().putBoolean("firstRun", false).apply();
// Toast.makeText(getApplicationContext(), "primeiro launcher", Toast.LENGTH_LONG).show();
// } else {
// Toast.makeText(getApplicationContext(), "segundo? terceiro?...", Toast.LENGTH_LONG).show();
// }

// if (url.equals("https://classroom.google.com/a/estudante.se.df.gov.br")) {
// new GuideView.Builder(this)
// .setTitle("Google Classroom")
// .setContentText("Esta aba serve para acessar sua conta do google classrom")
// .setGravity(Gravity.auto) //optional
// .setDismissType(DismissType.anywhere) //optional - default DismissType.targetView
// .setTargetView(findViewById(R.id.classroom))
// .setContentTextSize(12)//optional
// .setTitleTextSize(14)//optional
// .build()
// .show();
// } else if (url.equals("https://pt.wikipedia.org/")) {
// new GuideView.Builder(this)
// .setTitle("Wikipedia")
// .setContentText("Esta aba serve para acessar a wikipedia")
// .setGravity(Gravity.auto) //optional
// .setDismissType(DismissType.anywhere) //optional - default DismissType.targetView
// .setTargetView(findViewById(R.id.wikipedia))
// .setContentTextSize(12)//optional
// .setTitleTextSize(14)//optional
// .build()
// .show();
// }
}


Expand Down

0 comments on commit a624cd2

Please sign in to comment.