小编Adr*_*zin的帖子

通知会在每次进度更新时振动

在Android 8.0(Oreo)上,每当通知进度发生更新时,它都会振动.因此手机在此过程中会振动100次.这只发生在Android 8.0上所以我可以假设我有一些不当使用他们的API.我正在寻求帮助,以便在通知的每次进度更新中停止振动.这是我的代码:

建立通知

mNotifyManager = (NotificationManager) mActivity.getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) createChannel(mNotifyManager);
mBuilder = new NotificationCompat.Builder(mActivity, "FileDownload")
        .setSmallIcon(android.R.drawable.stat_sys_download)
        .setColor(ContextCompat.getColor(mActivity, R.color.colorNotification))
        .setContentTitle(mFile.getName())
        .setContentText(mActivity.getResources().getString(R.string.app_name))
        .setProgress(0, 0, true);
mNotifyManager.notify(mFile.getId().hashCode(), mBuilder.build());
Run Code Online (Sandbox Code Playgroud)

创建频道方法

  @TargetApi(26)
  private void createChannel(NotificationManager notificationManager) {
    String name = "FileDownload";
    String description = "Notifications for download status";
    int importance = NotificationManager.IMPORTANCE_MAX;

    NotificationChannel mChannel = new NotificationChannel(name, name, importance);
    mChannel.setDescription(description);
    mChannel.enableLights(true);
    mChannel.setLightColor(Color.BLUE);
    notificationManager.createNotificationChannel(mChannel);
  }
Run Code Online (Sandbox Code Playgroud)

onProgress

  @Override
  public void onProgress(File file, double progress, long downloadedBytes, long totalBytes) {
    mBuilder.setProgress(100, (int) (progress * 100), …
Run Code Online (Sandbox Code Playgroud)

notifications android

16
推荐指数
1
解决办法
2040
查看次数

使用 Dispatchers.IO 进行 Kotlin 协程测试

所以也许有一个教程来讨论这个问题,但是我读过的教程都没有为我解决这个问题。我有如下结构,正在尝试进行单元测试,但是当我去测试时,我总是失败,说明doSomthing()从未调用过 repo 方法。我最好的猜测是因为我在不同的上下文中启动了一个新的协程。那我该如何测试呢?

存储库

interface Repository {
    suspend fun doSomething(): String
}
Run Code Online (Sandbox Code Playgroud)

查看模型

class ViewModel(val repo: Repository) {
    val liveData = MutableLiveData<String>()
    fun doSomething {
    //Do something here
        viewModelScope.launch(Dispatchers.IO) {
            val data = repo.doSomething()
            withContext(Dispatchers.Main) {
                liveData.value = data
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

查看模型测试

class ViewModelTest {
    lateinit var viewModel: ViewModel
    lateinit var repo: Repository

    @Before
    fun setup() {
        Dispatchers.setMain(TestCoroutineDispatcher())
        repo = mock<Repository>()
        viewModel = ViewModel(repo)
    }

    @Test
    fun doSomething() = runBlockingTest {
        viewModel.doSomething()
        viewModel.liveData.test().awaitValue().assertValue {
            // assert …
Run Code Online (Sandbox Code Playgroud)

android unit-testing kotlin kotlin-coroutines

13
推荐指数
1
解决办法
4172
查看次数

Write join query with groupby in Scala ActiveRecord

I am trying to write a specific query in scala Active record. But it always returns nothing. I have read the wiki on the github page but it does not contain a lot of info on it. The query I am trying to write is

SELECT e.name, e.id, COUNT(pt.pass_id) as pass_count, e.start_date, e.total_passes_to_offer
FROM events e inner join passes p on e.id = p.event_id inner join pass_tickets pt on p.id = pt.pass_id where e.partner_id = 198 group by e.name, …
Run Code Online (Sandbox Code Playgroud)

activerecord scala join group-by

7
推荐指数
1
解决办法
197
查看次数

如果两个视图相同,为什么 TabView 显示空白屏幕?

我的应用程序中有一个 TabView,用于显示四个屏幕。两者相似但具有不同的数据源。如果我单击第一个选项卡 (EventsScreen),然后单击第三个选项卡 (MyBagScreen),则一切正常。如果我单击第一个选项卡 (EventsScreen),然后单击第二个选项卡 (EventsScreen),它只会加载一个空白屏幕(我认为它只是加载背景)。它们是两个不同的对象,为什么这不起作用?

AppView.swift

struct AppView: View {
    var body: some View {
        TabView {
            EventsScreen().environmentObject(EventsViewModel(repo: IncentivesRespository()))
                .tabItem {
                    Text("Barter")
                    Image("icon_barter")
            }
            EventsScreen().environmentObject(EventsViewModel(repo: OpportunityRepository()))
                .tabItem {
                    Text("Earn")
                    Image("icon_earn")
            }
            MyBagScreen().environmentObject(MyBagViewModel())
                .tabItem{
                    Text("My Bag")
                    Image("icon_bag")
            }
            AccountScreen().environmentObject(AccountViewModel())
                .tabItem {
                    Text("Account")
                    Image("icon_account")

            }
        }
        .onAppear(perform: {
            UITabBar.appearance().backgroundColor = .black
        })
            .navigationBarHidden(true)
    }
}
Run Code Online (Sandbox Code Playgroud)

事件屏幕

struct EventsScreen: View {

    @EnvironmentObject
    var viewModel: EventsViewModel

    let calendarManager = RKManager(calendar: Calendar.current, minimumDate: Date(), maximumDate: Date().addingTimeInterval(60*60*24*90), mode: 1)

    @State
    var currentPage: Int = 0 …
Run Code Online (Sandbox Code Playgroud)

ios swift swiftui

6
推荐指数
1
解决办法
455
查看次数