Skip to content

Commit

Permalink
Share is working 🙌 (#161)
Browse files Browse the repository at this point in the history
* Folder Structure changes

* BaseFragment$onViewCreated$1$onStateChanged$1.handleOnBackPressed ( FIXES #155 )

CombineKt$combineInternal$2$1.invokeSuspend ( FIXES #154 )

* Adding Share (FIXES #160)
  • Loading branch information
aiyu-ayaan authored Aug 14, 2023
1 parent 97c67ca commit 8546c77
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import com.atech.theme.isDark
import com.atech.theme.openCustomChromeTab
import com.atech.theme.openLinks
import com.atech.theme.openPlayStore
import com.atech.theme.openShareLink
import com.atech.theme.setStatusBarUiTheme
import com.atech.theme.showSnackBar
import com.google.android.material.bottomnavigation.BottomNavigationView
Expand Down Expand Up @@ -155,12 +156,14 @@ class MainActivity : AppCompatActivity(), ParentActivity, DrawerLocker,
R.id.nav_github -> this@MainActivity.openCustomChromeTab(resources.getString(com.atech.theme.R.string.github_link))
R.id.nav_whats_new -> this@MainActivity.openReleaseNotes()
R.id.nav_rate -> startReviewFlow()
R.id.nav_share -> openShareLink()
else -> NavigationUI.onNavDestinationSelected(menu, navController)
}
true
}
}


private fun handleDestinationChange() {
navController.onDestinationChange { destination ->
when (destination.id) {
Expand Down
29 changes: 27 additions & 2 deletions theme/src/main/java/com/atech/theme/share.kt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ fun Activity.openShareImageDeepLink(
putExtra(
Intent.EXTRA_STREAM, saveFileToCaches(
context, getBitMapUsingGlide(context, imageLink) ?: (ResourcesCompat.getDrawable(
context.resources, R.drawable.app_logo, null
context.resources, R.drawable.poster, null
) as BitmapDrawable).toBitmap()
)
)
Expand Down Expand Up @@ -140,4 +140,29 @@ fun saveFileToCaches(context: Context, bitmap: Bitmap): Uri? =
} catch (e: IOException) {
null
}
}
}

/**
*Extension function to share link
* @author Ayaan
* @since 4.0.3
*/
fun Activity.openShareLink() = this.startActivity(Intent.createChooser(Intent().apply {
action = Intent.ACTION_SEND
putExtra(
Intent.EXTRA_STREAM, saveFileToCaches(
this@openShareLink,
(ResourcesCompat.getDrawable(
this@openShareLink.resources, R.drawable.poster, null
) as BitmapDrawable).toBitmap()
)
)
putExtra(
Intent.EXTRA_TEXT,
"${resources.getString(R.string.app_share_content)} \n" + "${resources.getString(R.string.play_store_link)}$packageName"
)
type = "image/*"
putExtra(Intent.EXTRA_TITLE, resources.getString(R.string.share_app))

flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
}, null))
Binary file removed theme/src/main/res/drawable/app_logo.png
Binary file not shown.
Binary file added theme/src/main/res/drawable/poster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8546c77

Please sign in to comment.