Skip to content

Commit

Permalink
Update to version 3.1.2(beta)
Browse files Browse the repository at this point in the history
  • Loading branch information
Udhayarajan committed Dec 17, 2021
1 parent fa3ab60 commit ee08279
Show file tree
Hide file tree
Showing 43 changed files with 991 additions and 573 deletions.
16 changes: 16 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ android {
minSdkVersion 21
targetSdkVersion 31
versionCode 8
versionName "3.1.1"
versionName "3.1.2(beta)"
multiDexEnabled true


Expand Down Expand Up @@ -66,7 +66,7 @@ dependencies {
implementation "androidx.activity:activity:1.3.1"
implementation "androidx.fragment:fragment:1.3.6"
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
Expand All @@ -76,8 +76,9 @@ dependencies {

implementation 'androidx.preference:preference:1.1.1'
implementation 'com.google.firebase:firebase-config:21.0.1'
implementation 'com.google.firebase:firebase-database:20.0.1'
implementation 'com.google.firebase:firebase-database:20.0.2'

//Fetch
implementation "androidx.tonyodev.fetch2okhttp:xfetch2okhttp:3.1.6"
implementation "androidx.tonyodev.fetch2:xfetch2:3.1.6"

Expand All @@ -87,6 +88,7 @@ dependencies {

//Glide
implementation 'com.github.bumptech.glide:glide:4.12.0'
implementation 'androidx.browser:browser:1.3.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.12.0'


Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE"/>

<application
android:name=".VidSnapApp"
Expand Down Expand Up @@ -61,6 +60,8 @@

<service android:name=".network.Downloader"/>

<receiver android:name=".utility.CancelDownloadReceiver"/>

<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/com/mugames/vidsnap/VidSnapApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,21 @@

public class VidSnapApp extends Application {
public static final String NOTIFY_DOWNLOADING ="downloadingChannel";
public static final String NOTIFY_DOWNLOADER_SERVICE ="com.mugames.vidsnap.VidSnapApp.NOTIFY_DOWNLOADER_SERVICE";
public static final String NOTIFY_DOWNLOADED ="downloadedChannel";

@Override
public void onCreate() {
super.onCreate();
CreateNotificationChannel();
createNotificationChannel();
}

void CreateNotificationChannel(){
void createNotificationChannel(){
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
List<NotificationChannel> channelList=new ArrayList<>();
channelList.add(new NotificationChannel(NOTIFY_DOWNLOADING,"Downloading Notification Channel", NotificationManager.IMPORTANCE_LOW));
channelList.add(new NotificationChannel(NOTIFY_DOWNLOADED,"Notify when downloaded", NotificationManager.IMPORTANCE_HIGH));
channelList.add(new NotificationChannel(NOTIFY_DOWNLOADING,"On going download", NotificationManager.IMPORTANCE_LOW));
channelList.add(new NotificationChannel(NOTIFY_DOWNLOADED,"Completed download", NotificationManager.IMPORTANCE_HIGH));
channelList.add(new NotificationChannel(NOTIFY_DOWNLOADER_SERVICE,"Downloader service indicator",NotificationManager.IMPORTANCE_LOW));

NotificationManager notificationManager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
notificationManager.createNotificationChannels(channelList);
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/mugames/vidsnap/database/History.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import android.net.Uri;
import android.text.format.DateFormat;

import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
import androidx.room.TypeConverters;
Expand All @@ -42,7 +43,8 @@ public class History {
public String size;
public String uriString;
public String image;

@ColumnInfo(name = "source_url")
public String sourceUrl;
public History() {}


Expand All @@ -53,6 +55,7 @@ public History(DownloadDetails details, Uri uri) {
this.date = DateConverter.toDate( new Date().getTime());
this.size = String.valueOf(details.videoSize);
this.uriString = uri.toString();
sourceUrl = details.srcUrl;
image = UtilityClass.bitmapToString(details.getThumbNail());
}

Expand Down
93 changes: 38 additions & 55 deletions app/src/main/java/com/mugames/vidsnap/database/HistoryDatabase.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@

package com.mugames.vidsnap.database;

import static com.mugames.vidsnap.ui.viewmodels.MainActivityViewModel.STATIC_CACHE;
import static com.mugames.vidsnap.ui.viewmodels.MainActivityViewModel.db_name;
import static com.mugames.vidsnap.storage.AppPref.STATIC_CACHE;
import static com.mugames.vidsnap.storage.AppPref.db_name;

import android.content.Context;
import android.database.Cursor;
Expand All @@ -36,8 +36,9 @@
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

@Database(entities = {History.class}, version = 3)
@Database(entities = {History.class}, version = 4)
public abstract class HistoryDatabase extends RoomDatabase {


Expand All @@ -49,82 +50,64 @@ public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE HISTORY_NEW (id INTEGER NOT NULL , fileName TEXT, fileType TEXT, source TEXT, date TEXT, size TEXT, uriString TEXT, image TEXT, PRIMARY KEY(id))");
Cursor cursor = database.query("SELECT * FROM HISTORY");
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
String fileName = cursor.getString(1);
String fileType = cursor.getString(2);
String src = cursor.getString(3);
String date = cursor.getString(4);
String size = cursor.getString(5);
String uriString = cursor.getString(6);
byte[] thumbNail = cursor.getBlob(7);
int width = cursor.getInt(8);
int height = cursor.getInt(9);

fileType = fileType.replaceAll("\\.", "");
String thumbnailString = UtilityClass.bitmapToString(UtilityClass.bytesToBitmap(thumbNail, width, height));
String value = id + ",\"" + fileName + "\",\"" + fileType + "\",\"" + src + "\",\"" + date + "\",\"" + size + "\",\"" + uriString + "\",\"" + thumbnailString + "\"";
String value = migrateLogic1_3(cursor, 1, 2, 0);
database.execSQL("INSERT INTO HISTORY_NEW (id,fileName,fileType,source,date,size,uriString,image) VALUES(" + value + ")");
}
database.execSQL("DROP TABLE HISTORY");
database.execSQL("ALTER TABLE HISTORY_NEW RENAME TO HISTORY");
}
};

static Migration migration1_3 = new Migration(1, 3) {

static Migration migration2_3 = new Migration(2, 3) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE HISTORY_NEW (id INTEGER NOT NULL , fileName TEXT, fileType TEXT, source TEXT, date INTEGER, size TEXT, uriString TEXT, image TEXT, PRIMARY KEY(id))");
database.execSQL("CREATE TABLE HISTORY_NEW (id INTEGER NOT NULL , fileName TEXT, fileType TEXT, source TEXT, date INTRGER, size TEXT, uriString TEXT, image TEXT, PRIMARY KEY(id))");
Cursor cursor = database.query("SELECT * FROM HISTORY");
int i = 0;
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
String fileName = cursor.getString(1);
String fileType = cursor.getString(2);
String src = cursor.getString(3);
String date = cursor.getString(4);
String size = cursor.getString(5);
String uriString = cursor.getString(6);
byte[] thumbNail = cursor.getBlob(7);
int width = cursor.getInt(8);
int height = cursor.getInt(9);

fileType = fileType.replaceAll("\\.", "");
String thumbnailString = UtilityClass.bitmapToString(UtilityClass.bytesToBitmap(thumbNail, width, height));
Long lDate = parseForDate(date, ++i);
String value = id + ",\"" + fileName + "\",\"" + fileType + "\",\"" + src + "\"," + lDate + ",\"" + size + "\",\"" + uriString + "\",\"" + thumbnailString + "\"";
String value = migrateLogic1_3(cursor, 2, 3, i++);
database.execSQL("INSERT INTO HISTORY_NEW (id,fileName,fileType,source,date,size,uriString,image) VALUES(" + value + ")");
}
database.execSQL("DROP TABLE HISTORY");
database.execSQL("ALTER TABLE HISTORY_NEW RENAME TO HISTORY");
}
};

static Migration migration2_3 = new Migration(2, 3) {
static Migration migration3_4 = new Migration(3, 4) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase database) {
database.execSQL("CREATE TABLE HISTORY_NEW (id INTEGER NOT NULL , fileName TEXT, fileType TEXT, source TEXT, date INTRGER, size TEXT, uriString TEXT, image TEXT, PRIMARY KEY(id))");
Cursor cursor = database.query("SELECT * FROM HISTORY");
int i = 0;
while (cursor.moveToNext()) {
int id = cursor.getInt(0);
String fileName = cursor.getString(1);
String fileType = cursor.getString(2);
String src = cursor.getString(3);
String date = cursor.getString(4);
Long lDate = parseForDate(date, i++);
String size = cursor.getString(5);
String uriString = cursor.getString(6);
String thumbnailString = cursor.getString(7);
String value = id + ",\"" + fileName + "\",\"" + fileType + "\",\"" + src + "\"," + lDate + ",\"" + size + "\",\"" + uriString + "\",\"" + thumbnailString + "\"";
database.execSQL("INSERT INTO HISTORY_NEW (id,fileName,fileType,source,date,size,uriString,image) VALUES(" + value + ")");
}
database.execSQL("DROP TABLE HISTORY");
database.execSQL("ALTER TABLE HISTORY_NEW RENAME TO HISTORY");
database.execSQL("Alter table history add column source_url TEXT");
}
};

static String migrateLogic1_3(Cursor cursor, int from, int to, int i) {
int id = cursor.getInt(0);
String fileName = cursor.getString(1);
String fileType = cursor.getString(2);
String src = cursor.getString(3);
String date = cursor.getString(4);
String size = cursor.getString(5);
String uriString = cursor.getString(6);
if (from == 1 && to == 2) {
byte[] thumbNail = cursor.getBlob(7);
int width = cursor.getInt(8);
int height = cursor.getInt(9);

fileType = fileType.replaceAll("\\.", "");
String thumbnailString = UtilityClass.bitmapToString(UtilityClass.bytesToBitmap(thumbNail, width, height));
return id + ",\"" + fileName + "\",\"" + fileType + "\",\"" + src + "\",\"" + date + "\",\"" + size + "\",\"" + uriString + "\",\"" + thumbnailString + "\"";
} else if (from == 2 && to == 3) {
Long lDate = parseForDate(date, i);
String thumbnailString = cursor.getString(7);

return id + ",\"" + fileName + "\",\"" + fileType + "\",\"" + src + "\"," + lDate + ",\"" + size + "\",\"" + uriString + "\",\"" + thumbnailString + "\"";
}
return null;
}

private static Long parseForDate(String date, int index) {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
try {
Date date1 = simpleDateFormat.parse(date);
return date1.getTime() + index;
Expand All @@ -141,7 +124,7 @@ public static HistoryDatabase getInstance(Context context) {
synchronized (HistoryDatabase.class) {
if (instance == null) {
instance = Room.databaseBuilder(context.getApplicationContext(), HistoryDatabase.class, AppPref.getInstance(context).getCachePath(STATIC_CACHE) + db_name)
.addMigrations(migration1_2, migration2_3, migration1_3)
.addMigrations(migration1_2, migration2_3, migration3_4)
.build();
}
}
Expand Down
Loading

0 comments on commit ee08279

Please sign in to comment.