Commit e9cfa9dc authored by Schoumi's avatar Schoumi

Add Support Dialog

parent 9cb7bb6b
Pipeline #306 failed with stage
in 1 minute and 11 seconds
......@@ -49,7 +49,7 @@ public class Database extends SQLiteOpenHelper {
public static Database getInstance(Context context)
{
if(instance == null)
instance = new Database(context, "BloodDonation.db", null, 3);
instance = new Database(context, "BloodDonation.db", null, 4);
return instance;
}
......@@ -61,7 +61,7 @@ public class Database extends SQLiteOpenHelper {
public void onCreate(SQLiteDatabase db) {
db.execSQL("Create table if not exists user (" +
"id integer primary key autoincrement, name varchar(1024), city varchar(1024), postal varchar(10), gender INTEGER, blood varchar(10), D INTEGER, C INTEGER, E INTEGER, min_c INTEGER, min_e INTEGER, K INTEGER" +
",latitude REAL, longitude REAL);");
",latitude REAL, longitude REAL, show_support INTEGER);");
db.execSQL("Create table if not exists site (" +
"id integer primary key autoincrement, country INTEGER, address varchar(1024), city varchar(1024), details varchar(4096), mail varchar(1024), phone varchar(1024),"
+"siteName varchar(1024), siteId INTEGER, date INTEGER, latitude REAL, longitude REAL, type INTEGER, schedule INTEGER" +
......@@ -78,7 +78,6 @@ public class Database extends SQLiteOpenHelper {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//nothing to do right now
db.execSQL("Create table if not exists notification (" +
"id integer primary key autoincrement, siteId INTEGER, skip INTEGER " +
......@@ -87,6 +86,24 @@ public class Database extends SQLiteOpenHelper {
{
db.execSQL("Alter Table notification Add Column skip INTEGER;");
}
if(oldVersion <= 3) {
db.execSQL("Alter Table user Add Column show_support INTEGER;");
String[] column = {"id"};
Cursor cursor = db.query("user",column,null,null,null,null,null);
if(cursor.getCount() > 0) {
cursor.moveToFirst();
int userId;
userId = cursor.getInt(0);
cursor.close();
String whereClause = "id = ?";
String[] whereArgs = new String[1];
whereArgs[0] = String.valueOf(userId);
ContentValues values = new ContentValues();
values.put("show_support", false);
db.update("user", values, whereClause, whereArgs);
}
}
}
......@@ -108,7 +125,8 @@ public class Database extends SQLiteOpenHelper {
if(!isFirstTime())
{
int userId;
Cursor cursor = getReadableDatabase().query("user",null,null,null,null,null,null);
String[] column = {"id"};
Cursor cursor = getReadableDatabase().query("user",column,null,null,null,null,null);
cursor.moveToFirst();
userId = cursor.getInt(0);
String whereClause = "id = ?";
......@@ -119,6 +137,7 @@ public class Database extends SQLiteOpenHelper {
}
else
{
values.put("show_support",false);
getWritableDatabase().insert("user", null, values);
}
......@@ -545,4 +564,31 @@ public class Database extends SQLiteOpenHelper {
}
}
public boolean hasShownSupport(){
String[] column = {"show_support"};
Cursor cursor = getReadableDatabase().query("user",column,null,null,null,null,null);
if(cursor.getCount() > 0) {
cursor.moveToFirst();
boolean hasShown = cursor.getInt(0) != 0;
cursor.close();
return hasShown;
}
return false;
}
public void setHasShownSupport(){
String[] column = {"id"};
Cursor cursor = getReadableDatabase().query("user",column,null,null,null,null,null);
cursor.moveToFirst();
int userId;
userId = cursor.getInt(0);
cursor.close();
String whereClause = "id = ?";
String[] whereArgs = new String[1];
whereArgs[0] = String.valueOf(userId);
ContentValues values = new ContentValues();
values.put("show_support",true);
getWritableDatabase().update("user", values,whereClause, whereArgs);
}
}
......@@ -32,6 +32,7 @@ import fr.mobdev.blooddonation.Database;
import fr.mobdev.blooddonation.R;
import fr.mobdev.blooddonation.dialog.InformationDialog;
import fr.mobdev.blooddonation.dialog.PostDonationDialog;
import fr.mobdev.blooddonation.dialog.SupportDialog;
import fr.mobdev.blooddonation.fragment.AboutFragment;
import fr.mobdev.blooddonation.fragment.DonationFragment;
import fr.mobdev.blooddonation.fragment.DonationInfoFragment;
......@@ -66,6 +67,7 @@ import android.widget.PopupMenu;
import com.google.android.material.navigation.NavigationView;
import com.google.android.material.snackbar.Snackbar;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.List;
......@@ -208,6 +210,11 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
transaction.replace(R.id.fragment_container,maps);
transaction.commit();
setupToolbar(maps);
if(!Database.getInstance(this).hasShownSupport()){
SupportDialog dialog = new SupportDialog();
dialog.setCancelable(false);
dialog.show(getSupportFragmentManager(),null);
}
}
private void showEditInformation(boolean modify) {
......
/*
* Copyright (C) 2017 Anthony Chomienne, anthony@mob-dev.fr
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 3
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package fr.mobdev.blooddonation.dialog;
import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.DialogFragment;
import fr.mobdev.blooddonation.Database;
import fr.mobdev.blooddonation.R;
@SuppressLint("InflateParams")
public class SupportDialog extends DialogFragment {
public SupportDialog()
{
}
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.support_dialog, null);
ImageView tipeee = view.findViewById(R.id.tipeee);
tipeee.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = "https://tipeee.com/schoumi";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
});
ImageView liberapay = view.findViewById(R.id.liberapay);
liberapay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String url = "https://fr.liberapay.com/Schoumi";
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
startActivity(intent);
}
});
builder
.setTitle(R.string.information)
.setView(view)
.setPositiveButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Database.getInstance(getActivity()).setHasShownSupport();
}
}).setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialogInterface) {
Database.getInstance(getActivity()).setHasShownSupport();
}
});
return builder.create();
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:text="@string/initiative"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/tipeee"
android:src="@drawable/tipeee"
android:layout_width="match_parent"
android:layout_gravity="center_horizontal"
android:layout_height="100dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:gravity="center_horizontal"
android:text="@string/and"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/liberapay"
android:src="@drawable/liberapay_logo"
android:layout_width="match_parent"
android:layout_height="100dp" />
</LinearLayout>
\ No newline at end of file
......@@ -93,6 +93,9 @@
<string name="need_write">La Carte à besoin des droits en écriture/lecture sur le stockage externe</string>
<string name="retry">Réessayer</string>
<string name="home">Accueil</string>
<string name="information">Information</string>
<string name="initiative">Cette application est une initiative indépendante de l\'EFS. Vous pouvez soutenir son développement ainsi que d\'autre projet de son créateur grâce à</string>
<string name="and">et</string>
<string name="or_donate">ou grâce à Tipeee</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment