11package fr .shayfox .k_note .controller ;
22
3+ import android .content .Intent ;
34import android .content .pm .PackageInfo ;
45import android .content .pm .PackageManager ;
6+ import android .graphics .BitmapFactory ;
7+ import android .graphics .PorterDuff ;
8+ import android .graphics .drawable .BitmapDrawable ;
9+ import android .net .Uri ;
10+ import android .os .AsyncTask ;
511import android .os .Bundle ;
12+ import android .text .Spanned ;
13+ import android .widget .EditText ;
614import android .widget .TextView ;
15+ import android .widget .Toast ;
716
817import androidx .annotation .Nullable ;
18+ import androidx .appcompat .app .AlertDialog ;
919import androidx .appcompat .app .AppCompatActivity ;
20+ import androidx .constraintlayout .widget .ConstraintLayout ;
1021
1122import com .google .android .material .appbar .MaterialToolbar ;
23+ import com .google .android .material .snackbar .Snackbar ;
24+ import com .google .gson .Gson ;
25+ import com .google .gson .GsonBuilder ;
26+ import com .google .gson .JsonObject ;
27+
28+ import java .io .File ;
29+ import java .util .ArrayList ;
30+ import java .util .Arrays ;
31+ import java .util .List ;
32+ import java .util .concurrent .ExecutionException ;
1233
1334import fr .shayfox .k_note .R ;
35+ import fr .shayfox .k_note .manager .Response ;
36+ import fr .shayfox .k_note .model .Ingredient ;
37+ import fr .shayfox .k_note .model .Note ;
38+ import fr .shayfox .k_note .model .Tag ;
39+ import fr .shayfox .k_note .serializer .BitmapSerializer ;
40+ import fr .shayfox .k_note .utils .FileUtils ;
41+ import io .noties .markwon .Markwon ;
1442
1543public class InfoActivity extends AppCompatActivity {
1644
1745 public MaterialToolbar toolbar ;
18- public TextView mTextView ;
46+ public TextView mVersionTextView ;
47+
48+ public ConstraintLayout mChangeLogLayout , mAuthorLayout , mBugLayout ;
1949
50+ private int numberOfTaps ;
51+ private long timeMillisOfFirstClick ;
2052
2153 @ Override
2254 protected void onCreate (@ Nullable Bundle savedInstanceState ) {
@@ -31,6 +63,11 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
3163 finish ();
3264 });
3365
66+ mChangeLogLayout = findViewById (R .id .info_activity_changelog_layout );
67+ mAuthorLayout = findViewById (R .id .info_activity_author_layout );
68+ mBugLayout = findViewById (R .id .info_activity_bug_layout );
69+ mVersionTextView = findViewById (R .id .info_activity_version_textfield );
70+
3471 PackageManager manager = getApplicationContext ().getPackageManager ();
3572 PackageInfo info ;
3673 try {
@@ -40,8 +77,93 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
4077 throw new RuntimeException (e );
4178 }
4279 String version = info .versionName ;
43- mTextView = findViewById (R .id .info_activity_version_textfield );
44- mTextView .setText (version );
80+ mVersionTextView .setText (version );
81+
82+ mChangeLogLayout .setOnClickListener (view -> {
83+
84+ Response response = null ;
85+ try {
86+ response = getResponse ("https://api.github.com/repos/ShayF0x/K-Note/releases/tags/" +version );
87+ } catch (ExecutionException e ) {
88+ throw new RuntimeException (e );
89+ } catch (InterruptedException e ) {
90+ throw new RuntimeException (e );
91+ }
92+
93+ String message = "La mise à jour ne contient pas de note" ;
94+ if (response != null ){
95+ if (response .get_code () == 404 ){
96+ message = "Votre version n'est pas officielle" ;
97+ }else if (response .get_code () == 200 ){
98+ Gson gson = new Gson ();
99+ message = gson .fromJson (response .get_content (), JsonObject .class ).get ("body" ).getAsString ();
100+ }
101+ }
102+
103+ AlertDialog .Builder alertDialogBuilder = new AlertDialog .Builder (InfoActivity .this , R .style .PopupDialogTheme );
104+
105+ final Markwon markwon = Markwon .create (InfoActivity .this );
106+ final Spanned markdown = markwon .toMarkdown (message );
107+
108+ alertDialogBuilder .setMessage (markdown );
109+
110+ // set dialog message
111+ alertDialogBuilder .setCancelable (false ).setPositiveButton ("OK" , null );
112+
113+ // create alert dialog
114+ AlertDialog alertDialog = alertDialogBuilder .create ();
115+ // show it
116+ alertDialog .show ();
117+
118+ alertDialog .getButton (AlertDialog .BUTTON_POSITIVE ).setTextColor (getColor (R .color .secondary_font ));
119+
120+ });
121+
122+ mBugLayout .setOnClickListener (view -> {
123+ Intent browserIntent = new Intent (Intent .ACTION_VIEW , Uri .parse ("https://github.com/ShayF0x/K-Note/issues" ));
124+ startActivity (browserIntent );
125+ });
126+
127+ mAuthorLayout .setOnClickListener (view -> {
128+
129+ if (timeMillisOfFirstClick > 0 && (System .currentTimeMillis () - timeMillisOfFirstClick ) > 2000 )
130+ numberOfTaps = 1 ;
131+ else
132+ numberOfTaps ++;
133+ if (numberOfTaps == 1 )
134+ timeMillisOfFirstClick = System .currentTimeMillis ();
135+ if (numberOfTaps == 7 && (System .currentTimeMillis () - timeMillisOfFirstClick ) <= 2000 && !MainActivity .INSTANCE .mAppManager .hasNote ("Omelette au lait" )) {
136+ final Gson gson = new GsonBuilder ()
137+ .registerTypeAdapter (Note .class , new BitmapSerializer ())
138+ .create ();
139+ Toast .makeText (this , "Vous avez activé la recette de l'omelette au lait !" , Toast .LENGTH_SHORT ).show ();
140+ final Note note = new Note ("Omelette au lait" , "Qui a dit que dans une omelette on met pas de lait ?" ,
141+ BitmapFactory .decodeResource (getResources (), R .drawable .omelette ),
142+ new ArrayList <>(), new int []{0 , 5 , 0 }, new int []{0 , 5 , 0 }, new int []{0 , 0 , 0 },
143+ 2 ,
144+ new ArrayList <>(Arrays .asList (
145+ new Ingredient ("Sel" , 1 , "pincée" ),
146+ new Ingredient ("oeufs" , 4 , null ),
147+ new Ingredient ("lait" , 20 , Ingredient .Measure .CENTILITRE ),
148+ new Ingredient ("gruyère" , 30 , Ingredient .Measure .GRAMME )
149+ )),
150+ "ÉTAPE 1\n Dans un bol mélanger les œufs puis y incorporer le lait puis le gruyère et le sel.\n \n ÉTAPE 2\n Faire cuire environs 5 minutes.\n \n ÉTAPE 3\n Et vous obtenez une omelette très aérée et moelleuse." ,
151+ new ArrayList <>(Arrays .asList (
152+ "1 pôele" ,
153+ "1 bol" ,
154+ "1 cuillère en bois"
155+ )), null );
156+ FileUtils .writeFileExternalStorage ("Notes" + File .separator +note .getUUID ()+".json" , gson .toJson (note ), true );
157+ MainActivity .INSTANCE .mAppManager .addNote (note );
158+ }
159+
160+ });
161+
162+
163+ }
45164
165+ private Response getResponse (String src ) throws ExecutionException , InterruptedException {
166+ AsyncTask <String , Void , Response > async = new MainActivity .getResponseTask ().execute (src );
167+ return async .get ();
46168 }
47169}
0 commit comments