Skip to content
This repository has been archived by the owner on Jan 22, 2023. It is now read-only.

Commit

Permalink
new sdk version changes, api, deeplink url changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrwhoknows55 authored Jan 22, 2023
2 parents 2f66635 + 7922fac commit beeb841
Show file tree
Hide file tree
Showing 19 changed files with 155 additions and 80 deletions.
23 changes: 16 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ android {

defaultConfig {
applicationId "com.mrwhoknows.csgeeks"
minSdkVersion 22
minSdkVersion 23
targetSdkVersion 33
versionCode 2
versionName "2.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

buildConfigField "String", "BASE_API_URL", "\"https://csgeeks-blog-api.onrender.com/\""
buildConfigField "String", "BLOG_LINK_WITHOUT_HTTP", "\"jaypowar00.github.io/csgeeksblog\""
resValue "string", "blog_by_id_deeplink", "jaypowar00.github.io/csgeeksblog/post.html?id={articleID}"
resValue "string", "blog_author_deeplink", "jaypowar00.github.io/csgeeksblog/author.html?name={authorName}"
resValue "string", "blog_host_deeplink", "\"jaypowar00.github.io\""
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -38,13 +44,13 @@ android {
dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation 'androidx.core:core-ktx:1.9.0'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.appcompat:appcompat:1.6.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

implementation "com.google.android.material:material:1.6.1"
implementation "com.google.android.material:material:1.7.0"

//Retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
Expand All @@ -60,8 +66,8 @@ dependencies {
implementation "com.github.bumptech.glide:glide:4.12.0"

// Nav components
implementation "androidx.navigation:navigation-fragment-ktx:2.5.2"
implementation "androidx.navigation:navigation-ui-ktx:2.5.2"
implementation "androidx.navigation:navigation-fragment-ktx:2.5.3"
implementation "androidx.navigation:navigation-ui-ktx:2.5.3"

// Markown
implementation "io.noties.markwon:core:4.6.2"
Expand All @@ -70,6 +76,9 @@ dependencies {

// progress bar
implementation 'com.agrawalsuneet.androidlibs:dotsloader:1.4.2'

// splash screen
implementation 'androidx.core:core-splashscreen:1.0.0'
}

kapt {
Expand Down
20 changes: 17 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,29 @@
android:roundIcon="@mipmap/ic_launcher"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ui.home_page.MainActivity"
android:exported="false">
<activity
android:launchMode="singleTask"
android:name=".ui.home_page.MainActivity"
android:exported="true">
<nav-graph android:value="@navigation/blog_nav_graph" />
<intent-filter android:autoVerify="true">
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="http" />
<data android:scheme="https" />

<data android:host="@string/blog_host_deeplink" />
</intent-filter>
</activity>
<activity android:name=".ui.admin_page.AdminActivity"
android:exported="false">
<nav-graph android:value="@navigation/admin_nav_graph" />
</activity>
<activity android:name=".ui.SplashActivity"
<activity
android:theme="@style/Theme.App.Starting"
android:name=".ui.SplashActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mrwhoknows.csgeeks.api

import com.mrwhoknows.csgeeks.util.Constants.BASE_URL
import com.mrwhoknows.csgeeks.util.Constants.BASE_API_URL
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import retrofit2.Retrofit
Expand All @@ -16,13 +16,13 @@ class RetrofitInstance {
.addInterceptor(logging)
.build()
Retrofit.Builder()
.baseUrl(BASE_URL)
.baseUrl(BASE_API_URL)
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()
}
val api by lazy {
val api: BlogApi by lazy {
retrofit.create(BlogApi::class.java)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,52 +1,39 @@
package com.mrwhoknows.csgeeks.repository

import com.mrwhoknows.csgeeks.api.RetrofitInstance
import com.mrwhoknows.csgeeks.model.SendArticle
import com.mrwhoknows.csgeeks.model.*
import retrofit2.Response

class BlogRepository {
interface BlogRepository {

suspend fun getAllArticles() =
RetrofitInstance.api.getAllArticles()
suspend fun getAllArticles(): Response<ArticleList>

suspend fun getArticleById(id: String) =
RetrofitInstance.api.getArticleById(id)
suspend fun getArticleById(id: String): Response<Article>

suspend fun searchArticles(query: String) =
RetrofitInstance.api.searchArticles(query)
suspend fun searchArticles(query: String): Response<ArticleList>

suspend fun getArticlesByAuthor(authorName: String) =
RetrofitInstance.api.getArticlesByAuthor(authorName)
suspend fun getArticlesByAuthor(authorName: String): Response<ArticleList>

suspend fun orderArticlesBy(orderBy: String, order: String) =
RetrofitInstance.api.orderArticlesBy(orderBy, order)
suspend fun orderArticlesBy(orderBy: String, order: String): Response<ArticleList>

suspend fun orderArticlesBy(tag:String, orderBy: String, order: String) =
RetrofitInstance.api.orderArticlesBy(tag, orderBy, order)
suspend fun orderArticlesBy(tag: String, orderBy: String, order: String): Response<ArticleList>

suspend fun getAuthor(authorName: String) =
RetrofitInstance.api.getAuthor(authorName)
suspend fun getAuthor(authorName: String): Response<Author>

suspend fun createArticle(article: SendArticle, token: String) =
RetrofitInstance.api.createArticle(article, token)
suspend fun createArticle(article: SendArticle, token: String): Response<ResultResponse>

suspend fun updateArticle(id: String, article: SendArticle, token: String) =
RetrofitInstance.api.updateArticle(id, article, token)
suspend fun updateArticle(
id: String, article: SendArticle, token: String
): Response<ResultResponse>

suspend fun deleteArticle(id: String, token: String) =
RetrofitInstance.api.deleteArticle(id, token)
suspend fun deleteArticle(id: String, token: String): Response<ResultResponse>

suspend fun getArticleTags() =
RetrofitInstance.api.getTags()
suspend fun getArticleTags(): Response<ArticleTags>

suspend fun getArticleByTag(tag: String) =
RetrofitInstance.api.getArticleByTag(tag)
suspend fun getArticleByTag(tag: String): Response<ArticleList>

suspend fun login(username: String, passwd: String) =
RetrofitInstance.api.login(username, passwd)
suspend fun login(username: String, passwd: String): Response<LoginResponse>

suspend fun logoutUser(token: String) =
RetrofitInstance.api.logoutUser(token)
suspend fun logoutUser(token: String): Response<LoginResponse>

suspend fun isLoggedIn(token: String) =
RetrofitInstance.api.isLoggedIn(token)
suspend fun isLoggedIn(token: String): Response<LoginResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.mrwhoknows.csgeeks.repository

import com.mrwhoknows.csgeeks.api.RetrofitInstance
import com.mrwhoknows.csgeeks.model.SendArticle

class BlogRepositoryImpl : BlogRepository {

override suspend fun getAllArticles() =
RetrofitInstance.api.getAllArticles()

override suspend fun getArticleById(id: String) =
RetrofitInstance.api.getArticleById(id)

override suspend fun searchArticles(query: String) =
RetrofitInstance.api.searchArticles(query)

override suspend fun getArticlesByAuthor(authorName: String) =
RetrofitInstance.api.getArticlesByAuthor(authorName)

override suspend fun orderArticlesBy(orderBy: String, order: String) =
RetrofitInstance.api.orderArticlesBy(orderBy, order)

override suspend fun orderArticlesBy(tag:String, orderBy: String, order: String) =
RetrofitInstance.api.orderArticlesBy(tag, orderBy, order)

override suspend fun getAuthor(authorName: String) =
RetrofitInstance.api.getAuthor(authorName)

override suspend fun createArticle(article: SendArticle, token: String) =
RetrofitInstance.api.createArticle(article, token)

override suspend fun updateArticle(id: String, article: SendArticle, token: String) =
RetrofitInstance.api.updateArticle(id, article, token)

override suspend fun deleteArticle(id: String, token: String) =
RetrofitInstance.api.deleteArticle(id, token)

override suspend fun getArticleTags() =
RetrofitInstance.api.getTags()

override suspend fun getArticleByTag(tag: String) =
RetrofitInstance.api.getArticleByTag(tag)

override suspend fun login(username: String, passwd: String) =
RetrofitInstance.api.login(username, passwd)

override suspend fun logoutUser(token: String) =
RetrofitInstance.api.logoutUser(token)

override suspend fun isLoggedIn(token: String) =
RetrofitInstance.api.isLoggedIn(token)
}
11 changes: 6 additions & 5 deletions app/src/main/java/com/mrwhoknows/csgeeks/ui/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.ViewModelProvider
import com.mrwhoknows.csgeeks.databinding.ActivitySplashBinding
import com.mrwhoknows.csgeeks.repository.BlogRepository
import com.mrwhoknows.csgeeks.repository.BlogRepositoryImpl
import com.mrwhoknows.csgeeks.ui.admin_page.AdminActivity
import com.mrwhoknows.csgeeks.ui.home_page.MainActivity
import com.mrwhoknows.csgeeks.util.Constants
Expand All @@ -18,13 +19,13 @@ import com.mrwhoknows.csgeeks.viewmodels.BlogViewModelFactory

private const val TAG = "SplashActivity"

// TODO use new splash_screen api
class SplashActivity : AppCompatActivity() {

lateinit var viewModel: BlogViewModel
private val binding by lazy { ActivitySplashBinding.inflate(layoutInflater) }

override fun onCreate(savedInstanceState: Bundle?) {
val splashScreen = installSplashScreen()
super.onCreate(savedInstanceState)
setContentView(binding.root)
val appSettingPrefs = getSharedPreferences(Constants.APP_THEME_SHARED_PREFS, MODE_PRIVATE)
Expand All @@ -40,12 +41,13 @@ class SplashActivity : AppCompatActivity() {
val main = Intent(this, MainActivity::class.java)
val admin = Intent(this, AdminActivity::class.java)

val blogRepository = BlogRepository()
val blogRepository = BlogRepositoryImpl()
val viewModelFactory =
BlogViewModelFactory(
blogRepository
)
viewModel = ViewModelProvider(this, viewModelFactory).get(BlogViewModel::class.java)
viewModel = ViewModelProvider(this, viewModelFactory)[BlogViewModel::class.java]
splashScreen.setKeepOnScreenCondition { true }

Log.d(TAG, "isLoggedIn: " + loginInfo.isLoggedIn)
if (loginInfo.isLoggedIn) {
Expand All @@ -57,7 +59,6 @@ class SplashActivity : AppCompatActivity() {
} else {
navigateToActivity(main)
}

viewModel.isLoggedIn.observe(this) {
when (it) {
is Resource.Success -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.Snackbar
import com.mrwhoknows.csgeeks.R
import com.mrwhoknows.csgeeks.databinding.ActivityAdminBinding
import com.mrwhoknows.csgeeks.repository.BlogRepository
import com.mrwhoknows.csgeeks.repository.BlogRepositoryImpl
import com.mrwhoknows.csgeeks.ui.home_page.MainActivity
import com.mrwhoknows.csgeeks.util.Constants
import com.mrwhoknows.csgeeks.util.Constants.AUTHOR_NAME
Expand Down Expand Up @@ -60,7 +60,7 @@ class AdminActivity : AppCompatActivity() {
)
)

val blogRepository = BlogRepository()
val blogRepository = BlogRepositoryImpl()
val viewModelFactory =
BlogViewModelFactory(
blogRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import androidx.navigation.fragment.findNavController
import com.google.android.material.snackbar.Snackbar
import com.mrwhoknows.csgeeks.databinding.FragmentCreateArticleBinding
import com.mrwhoknows.csgeeks.model.SendArticle
import com.mrwhoknows.csgeeks.repository.BlogRepository
import com.mrwhoknows.csgeeks.repository.BlogRepositoryImpl
import com.mrwhoknows.csgeeks.util.Resource
import com.mrwhoknows.csgeeks.util.Util
import com.mrwhoknows.csgeeks.viewmodels.BlogViewModel
Expand Down Expand Up @@ -43,7 +43,7 @@ class EditArticleFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)

args = EditArticleFragmentArgs.fromBundle(requireArguments())
val blogRepository = BlogRepository()
val blogRepository = BlogRepositoryImpl()
val viewModelFactory =
BlogViewModelFactory(
blogRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import androidx.navigation.ui.NavigationUI
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.mrwhoknows.csgeeks.R
import com.mrwhoknows.csgeeks.databinding.ActivityMainBinding
import com.mrwhoknows.csgeeks.repository.BlogRepository
import com.mrwhoknows.csgeeks.repository.BlogRepositoryImpl
import com.mrwhoknows.csgeeks.util.Constants
import com.mrwhoknows.csgeeks.util.collapseKeyboardIfFocusOutsideEditText
import com.mrwhoknows.csgeeks.viewmodels.BlogViewModel
Expand All @@ -40,7 +40,7 @@ class MainActivity : AppCompatActivity() {
)
)

val blogRepository = BlogRepository()
val blogRepository = BlogRepositoryImpl()
val viewModelFactory =
BlogViewModelFactory(
blogRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import com.bumptech.glide.request.target.Target
import com.google.android.material.snackbar.Snackbar
import com.mrwhoknows.csgeeks.R
import com.mrwhoknows.csgeeks.databinding.FragmentArticleBinding
import com.mrwhoknows.csgeeks.repository.BlogRepository
import com.mrwhoknows.csgeeks.repository.BlogRepositoryImpl
import com.mrwhoknows.csgeeks.util.Constants
import com.mrwhoknows.csgeeks.util.Constants.BLOG_SITE_URL_WITH_HTTPS
import com.mrwhoknows.csgeeks.util.Resource
import com.mrwhoknows.csgeeks.util.Util
import com.mrwhoknows.csgeeks.viewmodels.BlogViewModel
Expand Down Expand Up @@ -48,13 +49,13 @@ class ArticleFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)
setHasOptionsMenu(true)

val blogRepository = BlogRepository()
val blogRepository = BlogRepositoryImpl()
val viewModelFactory =
BlogViewModelFactory(
blogRepository
)
viewModel =
ViewModelProvider(requireActivity(), viewModelFactory).get(BlogViewModel::class.java)
ViewModelProvider(requireActivity(), viewModelFactory)[BlogViewModel::class.java]

articleID = args.articleID

Expand All @@ -79,8 +80,7 @@ class ArticleFragment : Fragment() {
"dd, MMM yyyy hh:mm a"
)

val authorDeepLink =
"https://csgeeks-blog.000webhostapp.com/author.html?name=${data.author}"
val authorDeepLink = BLOG_SITE_URL_WITH_HTTPS + "/author.html?name=${data.author}"

val articleHeader =
"# ${data.title}\n![thumb](${data.thumbnail}) \n\nCreated by," +
Expand Down Expand Up @@ -136,7 +136,7 @@ class ArticleFragment : Fragment() {
type = "text/plain"
putExtra(
Intent.EXTRA_TEXT,
"Checkout awesome article: ${Constants.BLOG_SITE_URL}/post.html?id=$articleID"
"Checkout awesome article: ${Constants.BLOG_SITE_URL_WITHOUT_HTTPS}/post.html?id=$articleID"
)
}
startActivity(Intent.createChooser(intent, "Share The Article"))
Expand Down
Loading

0 comments on commit beeb841

Please sign in to comment.