Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Add link to original post ( closes #13 )
Browse files Browse the repository at this point in the history
  • Loading branch information
SuhasDissa committed Aug 20, 2023
1 parent 02a0a1d commit f59977a
Show file tree
Hide file tree
Showing 11 changed files with 446 additions and 197 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
{
"formatVersion": 1,
"database": {
"version": 6,
"identityHash": "2fe659ff924b9df55352ca23a333dfc9",
"entities": [
{
"tableName": "reddit_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `url` TEXT NOT NULL, `title` TEXT NOT NULL DEFAULT '', `is_video` INTEGER NOT NULL, `preview` TEXT NOT NULL DEFAULT '', `subreddit` TEXT NOT NULL DEFAULT '', `post_link` TEXT DEFAULT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "isVideo",
"columnName": "is_video",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "preview",
"columnName": "preview",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "subreddit",
"columnName": "subreddit",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "postLink",
"columnName": "post_link",
"affinity": "TEXT",
"notNull": false,
"defaultValue": "NULL"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "subreddit",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `icon_url` TEXT, `name` TEXT NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "iconUrl",
"columnName": "icon_url",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "lemmy_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `url` TEXT NOT NULL, `title` TEXT NOT NULL DEFAULT '', `is_video` INTEGER NOT NULL, `preview` TEXT NOT NULL DEFAULT '', `community` TEXT NOT NULL DEFAULT '', `instance` TEXT NOT NULL DEFAULT '', `post_link` TEXT DEFAULT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "url",
"columnName": "url",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "title",
"columnName": "title",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "isVideo",
"columnName": "is_video",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "preview",
"columnName": "preview",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "community",
"columnName": "community",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "instance",
"columnName": "instance",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "postLink",
"columnName": "post_link",
"affinity": "TEXT",
"notNull": false,
"defaultValue": "NULL"
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "community",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`community` TEXT NOT NULL, `instance` TEXT NOT NULL, `icon_url` TEXT, `name` TEXT NOT NULL, PRIMARY KEY(`community`, `instance`))",
"fields": [
{
"fieldPath": "id",
"columnName": "community",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "instance",
"columnName": "instance",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "iconUrl",
"columnName": "icon_url",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "name",
"columnName": "name",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"community",
"instance"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '2fe659ff924b9df55352ca23a333dfc9')"
]
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*******************************************************************************
Created By Suhas Dissanayake on 11/25/22, 7:42 AM
Copyright (c) 2022
https://github.com/SuhasDissa/
All Rights Reserved
******************************************************************************/

package app.suhasdissa.memerize.backend.database

import android.content.Context
Expand All @@ -24,10 +17,11 @@ import app.suhasdissa.memerize.backend.database.entity.RedditMeme

@Database(
entities = [RedditMeme::class, RedditCommunity::class, LemmyMeme::class, LemmyCommunity::class],
version = 5,
version = 6,
exportSchema = true,
autoMigrations = [
AutoMigration(from = 4, to = 5)
AutoMigration(from = 4, to = 5),
AutoMigration(from = 5, to = 6)
]
)
abstract class MemeDatabase : RoomDatabase() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*******************************************************************************
Created By Suhas Dissanayake on 7/29/23, 8:14 PM
Copyright (c) 2023
https://github.com/SuhasDissa/
All Rights Reserved
******************************************************************************/

package app.suhasdissa.memerize.backend.database.entity

import androidx.room.ColumnInfo
Expand All @@ -19,5 +12,6 @@ data class LemmyMeme(
@ColumnInfo(name = "is_video") override val isVideo: Boolean,
@ColumnInfo(name = "preview", defaultValue = "") override val preview: String,
@ColumnInfo(name = "community", defaultValue = "") val community: String,
@ColumnInfo(name = "instance", defaultValue = "") val instance: String
@ColumnInfo(name = "instance", defaultValue = "") val instance: String,
@ColumnInfo(name = "post_link", defaultValue = "NULL") override val postLink: String?
) : Meme
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*******************************************************************************
Created By Suhas Dissanayake on 8/4/23, 11:55 AM
Copyright (c) 2023
https://github.com/SuhasDissa/
All Rights Reserved
******************************************************************************/

package app.suhasdissa.memerize.backend.database.entity

interface Meme {
Expand All @@ -13,4 +6,5 @@ interface Meme {
val title: String
val isVideo: Boolean
val preview: String
val postLink: String?
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*******************************************************************************
Created By Suhas Dissanayake on 7/29/23, 8:14 PM
Copyright (c) 2023
https://github.com/SuhasDissa/
All Rights Reserved
******************************************************************************/

package app.suhasdissa.memerize.backend.database.entity

import androidx.room.ColumnInfo
Expand All @@ -18,5 +11,6 @@ data class RedditMeme(
@ColumnInfo(name = "title", defaultValue = "") override val title: String,
@ColumnInfo(name = "is_video") override val isVideo: Boolean,
@ColumnInfo(name = "preview", defaultValue = "") override val preview: String,
@ColumnInfo(name = "subreddit", defaultValue = "") val subreddit: String
@ColumnInfo(name = "subreddit", defaultValue = "") val subreddit: String,
@ColumnInfo(name = "post_link", defaultValue = "NULL") override val postLink: String?
) : Meme
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*******************************************************************************
Created By Suhas Dissanayake on 8/3/23, 6:44 PM
Copyright (c) 2023
https://github.com/SuhasDissa/
All Rights Reserved
******************************************************************************/

package app.suhasdissa.memerize.backend.model

import kotlinx.serialization.SerialName
Expand All @@ -25,5 +18,6 @@ data class Post(
@SerialName("id") var id: Int? = null,
@SerialName("name") var name: String? = null,
@SerialName("url") var url: String? = null,
@SerialName("thumbnail_url") var thumbnailUrl: String? = null
@SerialName("thumbnail_url") var thumbnailUrl: String? = null,
@SerialName("ap_id") var postLink: String? = null
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*******************************************************************************
Created By Suhas Dissanayake on 8/4/23, 9:06 PM
Copyright (c) 2023
https://github.com/SuhasDissa/
All Rights Reserved
******************************************************************************/

package app.suhasdissa.memerize.backend.repositories

import android.util.Log
Expand Down Expand Up @@ -60,7 +53,8 @@ class LemmyMemeRepositoryImpl(
false,
url,
community.name,
community.instance
community.instance,
post.post?.postLink
)
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
/*******************************************************************************
Created By Suhas Dissanayake on 8/4/23, 9:06 PM
Copyright (c) 2023
https://github.com/SuhasDissa/
All Rights Reserved
******************************************************************************/

package app.suhasdissa.memerize.backend.repositories

import android.util.Log
Expand Down Expand Up @@ -57,7 +50,17 @@ class RedditMemeRepositoryImpl(
val url = child.Childdata.url
if (url.matches(imageRegex)) {
val id = url.hashCode().toString()
memeList.add(RedditMeme(id, url, child.Childdata.title, false, "", subreddit))
memeList.add(
RedditMeme(
id,
url,
child.Childdata.title,
false,
"",
subreddit,
child.Childdata.permalink
)
)
} else if (url.contains("v.redd.it") || child.Childdata.preview?.redditVideo?.dash_url != null) {
val dashUrl = child.Childdata.secure_media?.reddit_video?.dash_url
?: child.Childdata.preview?.redditVideo?.dash_url
Expand All @@ -71,7 +74,8 @@ class RedditMemeRepositoryImpl(
child.Childdata.title,
true,
previewUrl.replace("&", "&"),
subreddit
subreddit,
child.Childdata.permalink
)
)
}
Expand Down
Loading

0 comments on commit f59977a

Please sign in to comment.