1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 package com.example.android.bubbles 17 18 import android.os.Bundle 19 import android.widget.ImageView 20 import android.widget.TextView 21 import androidx.appcompat.app.AppCompatActivity 22 import androidx.fragment.app.transaction 23 import com.example.android.bubbles.ui.chat.ChatFragment 24 import com.example.android.bubbles.ui.photo.PhotoFragment 25 26 /** 27 * Entry point of the app when it is launched as an expanded Bubble. 28 */ 29 class BubbleActivity : AppCompatActivity(), NavigationController { 30 onCreatenull31 override fun onCreate(savedInstanceState: Bundle?) { 32 super.onCreate(savedInstanceState) 33 setContentView(R.layout.bubble_activity) 34 val id = intent.data.lastPathSegment.toLongOrNull() ?: return 35 if (savedInstanceState == null) { 36 supportFragmentManager.transaction(now = true) { 37 replace(R.id.container, ChatFragment.newInstance(id, false)) 38 } 39 } 40 } 41 openChatnull42 override fun openChat(id: Long) { 43 throw UnsupportedOperationException("BubbleActivity always shows a single chat thread.") 44 } 45 openPhotonull46 override fun openPhoto(photo: Int) { 47 // In an expanded Bubble, you can navigate between Fragments just like you would normally do in a normal 48 // Activity. Just make sure you don't block onBackPressed(). 49 supportFragmentManager.transaction { 50 addToBackStack(null) 51 replace(R.id.container, PhotoFragment.newInstance(photo)) 52 } 53 } 54 updateAppBarnull55 override fun updateAppBar(showContact: Boolean, hidden: Boolean, body: (name: TextView, icon: ImageView) -> Unit) { 56 // The expanded bubble does not have an app bar. Ignore. 57 } 58 } 59