Skip to content

Commit

Permalink
Add parameter for nearby
Browse files Browse the repository at this point in the history
  • Loading branch information
cooltey committed Dec 1, 2023
1 parent e30689f commit 8ace902
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
8 changes: 6 additions & 2 deletions app/src/main/java/org/wikipedia/nearby/NearbyActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ package org.wikipedia.nearby

import android.content.Context
import android.content.Intent
import android.location.Location
import org.wikipedia.activity.SingleFragmentActivity
import org.wikipedia.dataclient.WikiSite
import org.wikipedia.extensions.parcelableExtra

class NearbyActivity : SingleFragmentActivity<NearbyFragment>() {

public override fun createFragment(): NearbyFragment {
return NearbyFragment.newInstance(intent.getParcelableExtra(EXTRA_WIKI)!!)
return NearbyFragment.newInstance(intent.parcelableExtra(EXTRA_WIKI)!!, intent.parcelableExtra(EXTRA_LOCATION))
}

companion object {
const val EXTRA_WIKI = "wiki"
fun newIntent(context: Context, wiki: WikiSite): Intent {
const val EXTRA_LOCATION = "location"
fun newIntent(context: Context, wiki: WikiSite, location: Location? = null): Intent {
return Intent(context, NearbyActivity::class.java)
.putExtra(EXTRA_WIKI, wiki)
.putExtra(EXTRA_LOCATION, location)
}
}
}
5 changes: 3 additions & 2 deletions app/src/main/java/org/wikipedia/nearby/NearbyFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.graphics.PorterDuffXfermode
import android.graphics.Rect
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.Drawable
import android.location.Location
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand Down Expand Up @@ -389,9 +390,9 @@ class NearbyFragment : Fragment(), LinkPreviewDialog.Callback {
val MARKER_WIDTH = DimenUtil.roundedDpToPx(48f)
val MARKER_HEIGHT = DimenUtil.roundedDpToPx(60f)

fun newInstance(wiki: WikiSite): NearbyFragment {
fun newInstance(wiki: WikiSite, location: Location?): NearbyFragment {
return NearbyFragment().apply {
arguments = bundleOf(NearbyActivity.EXTRA_WIKI to wiki)
arguments = bundleOf(NearbyActivity.EXTRA_WIKI to wiki, NearbyActivity.EXTRA_LOCATION to location)
}
}

Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/org/wikipedia/page/PageFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1501,8 +1501,9 @@ class PageFragment : Fragment(), BackPressedHandler, CommunicationBridge.Communi

override fun onViewOnMapSelected() {
title?.let {
if (page?.pageProperties?.geo != null) {
requireActivity().startActivity(NearbyActivity.newIntent(requireContext(), it.wikiSite))
val location = page?.pageProperties?.geo
if (location != null) {
requireActivity().startActivity(NearbyActivity.newIntent(requireContext(), it.wikiSite, location))
} else {
FeedbackUtil.showMessage(this@PageFragment, getString(R.string.action_item_view_on_map_unavailable))
}
Expand Down

0 comments on commit 8ace902

Please sign in to comment.